PHP cURL请求primary_ip与cURL url不同


PHP cURL request primary_ip is different than cURL url

通过PHP发出curl请求时,curl得到"无法连接到主机"。当我转储curl信息时,primary_ip不是所请求服务器的ip。

$soapURL ="www.google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $soapURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$header[] = "SOAPAction: ". "";
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: text/xml; charset=utf-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
echo curl_getinfo($ch) . '<br/>';
echo curl_errno($ch) . '<br/>';
echo curl_error($ch) . '<br/>';
$info = curl_getinfo($ch);
var_dump($info);

这在我的测试服务器上工作得很好,但在生产服务器上不行。在生产服务器上,我得到的响应如下:

数组

7

无法连接到主机Array (23) {["url"]=>字符串(21),http://www.google.com"("content_type" =比;零("http_code" =比;int(0)("header_size" =比;int(0)("requestrongize" =比;int(0)("filetime" =比;int(1)("ssl_verify_result" =比;int(0)("redirect_count" =比;int(0)("total_time" =比;浮动(0)("namelookup_time" =比;浮动(2.7 e-5)("connect_time" =比;浮动(0)("pretransfer_time" =比;浮动(0)("size_upload" =比;浮动(0)("size_download" =比;浮动(0)("speed_download" =比;浮动(0)("speed_upload" =比;浮动(0)("download_content_length" =比;浮子(1)("upload_content_length" =比;浮子(1)("starttransfer_time" =比;浮动(0)("redirect_time" =比;浮动(0)("redirect_url" =比;字符串(0)";"("primary_ip" =比;字符串(10)"10.1.99.87"("certinfo" =比;数组(0){}}

primary_ip => 10.1.99.87是我的本地机器(没有运行这个PHP代码)。看起来curl试图连接到我的本地机器,而不是我给它的url。我在另一台电脑上尝试了这个,IP仍然是我的机器,它没有改变到新机器的IP。

当我使用测试服务器,我得到:

数组

0

array(23) {["url"]=>字符串(21),http://www.google.com"("content_type" =比;字符串(24)"text/html;charset = UTF-8"("http_code" =比;int(405)("header_size" =比;int(260)("requestrongize" =比;int(948)("filetime" =比;int(1)("ssl_verify_result" =比;int(0)("redirect_count" =比;int(0)("total_time" =比;浮动(0.120098)("namelookup_time" =比;浮动(0.029716)("connect_time" =比;浮动(0.073289)("pretransfer_time" =比;浮动(0.073292)("size_upload" =比;浮动(815)("size_download" =比;浮动(1453)("speed_download" =比;浮动(12098)("speed_upload" =比;浮动(6786)("download_content_length" =比;浮动(1453)("upload_content_length" =比;浮动(0)("starttransfer_time" =比;浮动(0.119125)("redirect_time" =比;浮动(0)("redirect_url" =比;字符串(0)";"("primary_ip" =比;字符串(14)"74.125.198.106"("certinfo" =比;数组(0){}}

这是应该发生的。

过去为我的机器设置的http_proxy设置了Linux环境变量,我将其设置为空。另外,从命令行调用curl也可以正常工作。它只是php尝试进行的任何失败的curl调用。

类似问题的变通解决方案

SUSE特别是SLES 11有一些代理设置,您可以像我一样在目录中或通过YAST访问。更改这些设置并启用或禁用代理将影响通过Linux中的命令行进行的调用,但不会影响通过PHP进行的curl调用。重新启动Apache也没有改变任何东西。PHP仍然为http_proxy设置了环境变量。在我通过YAST删除所有代理设置后重新启动整个服务器(init 6),为我修复了代理问题。仅仅禁用代理是不够的。我必须在yast中清除代理设置