我看到一个非常奇怪的问题,我正在构建一个PHP应用程序。PHP CURL超时但CLI CURL工程
我在我的开发服务器(Windows 7 64位)sometestsite.com
和endpoint.sometestsite.com
上有2个虚拟主机。
在我的hosts
文件中,我配置了sometestsite.com
和endpoint.sometestsite.com
指向127.0.0.1
。
当服务器使用PHP 5.4.9作为fcgi模块运行Apache 2.4.2时,一切正常。
然后我删除了Apache并安装了nginx-1.2.5(windows build)。我得到了php-cgi.exe作为服务运行,并且一切似乎都很好。
问题是从以前工作的sometestsite.com
到endpoint.sometestsite.com
的CURL调用将超时。
然后我感动的是一段代码本身的一个小PHP文件来进行测试:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://endpoint.sometestsite.com/test');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('provider' => urlencode('provider'),
'key' => urlencode('asdf')));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Execute and get the data back
$result = curl_exec($ch);
var_dump($result);
这是我收到的PHP日志:
PHP Fatal error: Maximum execution time of 30 seconds exceeded in D:\www\test5.php on line 22
PHP Stack trace:
PHP 1. {main}() D:\www\test5.php:0
但是,如果我跑使用CLI CURL(通过Git Bash)的相同请求,它工作正常:
$ curl -X POST 'http://endpoint.sometestsite.com/test' -d'provider=provider&key=asdf'
{"test": "OK"}
这很奇怪,因为PHP是e xactly相同的版本,并具有与使用Apache时相同的配置。
我不确定这是Web服务器配置问题还是PHP CURL的问题。
任何人都可以提供一些见解/过去的经验,为什么发生这种情况?
你能告诉我们D:\ www \ test5.php的第22行是什么吗? – Sherif
@GoogleGuy:第22行实际上是// //执行并获取数据(我在CURL请求之前有一些其他代码,但它们只回显出一些字符串)。所以看起来'curl_exec()'超时。 – F21
对,这是你问题的一个重要部分。将它包含在你的代码中会对你有帮助,因为它是导致错误的原因。 – Sherif