PHP cURL XML示例有时在大多数情况下返回空白
以下是我的代码示例:PHP cURL XML示例有时在大多数情况下返回空白,php,xml,unix,curl,Php,Xml,Unix,Curl,以下是我的代码示例: 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
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");
$XML=”
密码短语
";
$reply=xmlPostStore($XML,”http://www.urlhere.com/test.php", "80");
php只是一个简单的XML返回:
echo "<?xml version='1.0' encoding='utf-8'?>
<response>
<config>
<test>it works</test>
</config>
</response>";
echo”
它起作用了
";
当我在一台服务器上进行测试时,它100%都能正常工作。我收到回复,没有问题
当我在主服务器上测试它时,它不会返回任何内容,大多数情况下,大约98%的时间它是空白的。如果没有任何代码更改,它将随机工作并随机停止。我被难住了。结果证明,我认为打开防火墙允许传入和传出连接只是允许传入,而不是传出。我还在resolv.conf下解决了一个DNS错误,现在一切正常。“有些时候,大部分时间,98%的时间”?那么,您在哪里回显
$reply
变量?它正在存储返回的数据@MarcB真有趣!但是试着找出他的问题:我在回应$reply,它确实在一台服务器上说“它可以工作”。另一台服务器仍然为空。我甚至禁用了两个防火墙,但它仍然不工作。很抱歉,我没有添加最后一段代码,但它就在那里。