我有PHP脚本将请求发布到远程API.如果响应时间超过大约200秒,那么我只会在响应中获得内容长度为零.我想弄清楚为什么会这样.
为了解决这个问题,我已经在Apache和PHP的配置文件中设置了每个可想到的变量,设置为超过300秒,以解决这个问题,如下面的第一个答案所建议的那样.我设置为300秒的东西:
尽管我仍然在200秒左右的时间内始终获得零内容长度响应.但是,如果不到200秒,问题就不会发生.
下面我将介绍如何设置代码.
会发生什么是crontab在我们的服务器上运行shell脚本,该脚本使用/ usr/bin/curl调用localhost URI.localhost URI由Apache提供,是一个PHP文件,它本身包含以下代码,后者又使用cURL调用远程API.我们发布大约10KB的XML,期望以块的形式接收大约135KB.
这是请求代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->_xml_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
我在Apache日志记录中打开了调试,下面是我们得到的.在此示例中,请求在19:48:00发送,响应在19:51:23返回,仅在200秒之后.
* About to connect() to api.asdf.com port 443 (#0)
* Trying 555.555.555.555... * connected
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using RC4-SHA
* Server certificate:
* subject: snip
* start date: 2014-03-12 10:22:02 GMT
* expire date: 2015-04-16 12:32:58 GMT
* subjectAltName: api.asdf.com matched
* issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Organization Validation CA - G2
* SSL certificate verify ok.
> POST /xmlservlet HTTP/1.1
Host: api.asdf.com
Accept: */*
Content-Type: text/xml
Content-Length: 10773
Expect: 100-continue
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/xml
< Server: Microsoft-IIS/7.5
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Thu, 06 Nov 2014 19:51:23 GMT
< Content-Length: 0
<
* Connection #0 to host api.asdf.com left intact
* Closing connection #0
Run Code Online (Sandbox Code Playgroud)
我想知道这段代码是否有问题,或者我可能在服务器设置中遗漏的东西,可能导致内容长度在200秒后回归零.
| 归档时间: |
|
| 查看次数: |
2005 次 |
| 最近记录: |