---更新的底部,它涉及到CURLOPT_COOKIE -PHP卷曲超时,但UNIX卷翘不
我深化发展我的本地机器(192.168.1.103)上,和我有一个PHP使用CURL调用来获取由远程脚本返回的标题和内容的脚本。
我已经安装了必须返回其内容的远程脚本的两个副本:
- 一个在本地计算机上,在同一个虚拟主机下。 (http://192.168.1.103/test/output_script.php)
- 一个在远程服务器上。 (http://site.com/text/outputscript.php)
当我尝试从远程服务器获取内容时,CURL脚本非常适用,但在尝试从本地服务器获取内容时完全超时。
的冗长的PHP卷曲是:
* About to connect() to 192.168.1.103 port 80 (#0)
* Trying 192.168.1.103... * connected
* Connected to 192.168.1.103 (192.168.1.103) port 80 (#0)
> GET /app/getContent HTTP/1.1
Host: 192.168.1.103
Accept: */*
Cookie: PHPSESSID=u8spbervheh3tcrv62gcnc2j72
* Operation timed out after 5001 milliseconds with 0 bytes received
* Closing connection #0
注意,URI是rewrited具有以下.htaccess文件(两个位置):
RewriteEngine on
RewriteBase /cms/client1/public_html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
另外请注意,我已经激活重写日志并比较请求以确保mod_rewrite动作在所有情况下完全相同。 (我100%肯定它不是一个重写麻烦)
如果我尝试使用Ubuntu下卷曲应用获取的文件,效果很好:
$ curl -v --cookie PHPSESSID=u8spbervheh3tcrv62gcnc2j72 http://192.168.1.103/app/getContent
* About to connect() to 192.168.1.103 port 80 (#0)
* Trying 192.168.1.103... connected
* Connected to 192.168.1.103 (192.168.1.103) port 80 (#0)
> GET /app/getContent HTTP/1.1
> User-Agent: curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: 192.168.1.103
> Accept: */*
> Cookie: PHPSESSID=u8spbervheh3tcrv62gcnc2j72
>
< HTTP/1.1 403 Forbidden
< Date: Thu, 24 Feb 2011 21:40:17 GMT
< Server: Apache/2.2.16 (Ubuntu)
< X-Powered-By: PHP/5.3.3-1ubuntu9.3
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Vary: Accept-Encoding
< Content-Length: 82
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host 192.168.1.103 left intact
* Closing connection #0
WT_AUTH non défini. (strictement aucune authentification actuellement en session)
403错误和WT_AUTH含量我期望得到的,而不是我用PHP的超时。
这也是相同的(希望&正确的)结果我收到如果使用远程服务器上的PHP卷曲:
* About to connect() to site.com port 80 (#0)
* Trying 123.123.123.123... * connected
* Connected to site.com (123.123.123.123) port 80 (#0)
> GET /app/getContent HTTP/1.1
Host: site.com
Accept: */*
Cookie: PHPSESSID=u8spbervheh3tcrv62gcnc2j72
< HTTP/1.1 403 Forbidden
< Date: Thu, 24 Feb 2011 21:45:30 GMT
< Server: Apache/2.2.16 (Debian) DAV/2 SVN/1.6.12 mod_fcgid/2.3.6
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Content-Length: 28
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host site.com left intact
* Closing connection #0
而且我也将得到同样的事情,如果我直接访问192.168.1.103/app/getContent在我的浏览器中。
最后,我还相信,该脚本的getContent通过把日志在它的工作。奇怪的部分是,如果我在16:45:00开始请求,并且超时发生在16:45:05,那么getContent脚本中记录的数据将在16:45:05过期。所以就好像CURL在“开放”状态下保持联系。当连接关闭时,php脚本被允许启动。
我的任何想法都无法在本地使用?
在你想看看PHP代码的情况下,这里的相关部分:
$ressource = curl_init();
curl_setopt($ressource, CURLOPT_URL, $destinationUrl);
curl_setopt($ressource, CURLOPT_VERBOSE, true);
$handle = fopen(FRAMEWORK_ROOT . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'curl_debug.txt', 'w');
curl_setopt($ressource, CURLOPT_STDERR, $handle);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ressource, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ressource, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ressource, CURLOPT_RETURNTRANSFER, TRUE); //retourn content
curl_setopt($ressource, CURLOPT_HEADER, TRUE); //get HTTP headers
curl_setopt($ressource, CURLOPT_COOKIE, session_name() . '=' . session_id());
curl_setopt($ressource, CURLOPT_TIMEOUT, 5);
echo "\n<br />" . date('Y/m/d H:i:s');
$httpResponse = curl_exec($ressource);
echo "\n<br />" . date('Y/m/d H:i:s');
if(curl_errno($ressource) != 0)
throw new Core_Exc_Def(curl_error($ressource)); // WILL THROW AN ERROR ON 192.168.1.103, BUT NOT ON THE REMOTE SITE.
滑稽的事实:加入超时之前,负载量为无限。当地的网站没有回应,甚至还有其他网页。我需要重新启动Apache服务器,以便能够再次访问该网站...
更新:
如果我评论该行:
curl_setopt($ressource, CURLOPT_COOKIE, session_name() . '=' . session_id());
它的“工作”(这会导致另一个问题,但没有什么与超时有关)。 这两个脚本都在同一个虚拟主机上,并共享相同的会话,但不应创建CURL TimeOut?!
curl_setopt($的ressource,CURLOPT_COOKIE,会话名称() 。'='。md5(session_id()。time())); – TarranJones 2015-01-29 08:52:22