2013-01-04 37 views
2

這裏是我的代碼示例:PHP捲曲XML例如有時會返回空白,大部分時間

function xmlPostStore($post_xml, $url, $port) { 
    $ch = curl_init(); // initialize curl handle 
    curl_setopt($ch, CURLOPT_URL, $url); // set url to post to 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable 
    curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number 
    curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields 
    $data = curl_exec($ch); 
    curl_close($ch); 
    return $data; 
} 

什麼我送:

$XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?> 
     <SendConfig> 
      <Request> 
       <key>passphrase</key> 
      </Request> 
     </SendConfig>"; 

$reply = xmlPostStore($XML, "http://www.urlhere.com/test.php", "80"); 

test.php的只是一個簡單的XML返回:

echo "<?xml version='1.0' encoding='utf-8'?> 
<response> 
    <config> 
     <test>it works</test> 
    </config> 
</response>"; 

當我在一臺服務器上測試它時,它在100%的時間內工作。我收到回覆,並沒有問題。

當我在我們的主服務器上測試它時,大部分時間它都沒有返回任何東西,大約98%的時間都是空白的。如果沒有任何代碼更改,它將隨機工作並隨機停止。我很難過。

+1

「有時,大部分時間,98%的時間」? –

+0

好吧,你在迴應'$ reply'變量嗎?它存儲返回的數據! –

+0

@MarcB這很有趣!但試圖找出他的問題:D –

回答

1

原來我認爲打開防火牆允許傳入和傳出連接只允許傳入而不傳出。我還解決了resolv.conf下的DNS錯誤,現在事情正常運行。