为什么Apache在200秒后将零内容长度返回给PHP POST请求?(Why is Apache returning a zero content length after 200 seconds

编程入门 行业动态 更新时间:2024-10-24 01:55:21
为什么Apache在200秒后将零内容长度返回给PHP POST请求?(Why is Apache returning a zero content length after 200 seconds to a PHP POST request?)

我有PHP脚本将请求发布到远程API。 如果响应需要超过200秒的时间才能返回,那么我只在响应中得到一个零长度的内容。 我想弄清楚为什么会这样。

为了解决这个问题,我已经将Apache和PHP的配置文件中的所有可以设想的变量设置为超过300秒来解决这个问题,正如下面的第一个答案所建议的。 我已经设置为300秒的事情:

Apache超时 Apache keep_alive时间 PHP max_reponse_time PHP session.cache_expire时间 PHP max_execution_time

尽管如此,我仍然始终在200秒内获得零内容长度回复。 但是如果花费少于200秒,问题就不会发生。

下面我介绍我们的代码是如何设置的。

会发生什么情况是,crontab在我们的服务器上运行一个shell脚本,该脚本使用/ usr / bin / curl调用localhost URI。 本地主机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);

我打开了我们的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

我想知道这段代码有什么问题,或者我可能在服务器设置中错过了一些内容,导致内容长度在200秒后回到零。

I have PHP script that posts a request to a remote API. If the response takes longer than about 200 seconds to come back, then I just get a content-length of zero in the response. I am trying to figure out why that is happening.

In an attempt to resolve this issue, I have set every conceivable variable in Apache's and PHP's config files set to longer than 300 seconds to combat this, as recommended by the first answer below. The things I have set to 300 seconds:

Apache timeout Apache keep_alive time PHP max_reponse_time PHP session.cache_expire time PHP max_execution_time

Despite that I still consistently get zero content length responses right around the 200-second mark. However if it takes less than 200 seconds the problem does not occur.

Below I describe how our code is set up.

What happens is that crontab runs a shell script on our server, which calls a localhost URI using /usr/bin/curl. The localhost URI is served by Apache and is a PHP file that itself contains the below code, which in turn uses cURL to call out to the remote API. We POST about 10KB of XML and expect to receive about 135KB back, in chunks.

Here is the request code:

$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);

I turned on debugging in our Apache logging and below is what we get. In this example the request was sent at 19:48:00 and the response comes back at 19:51:23, just over 200 seconds later.

* 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

I would like to know if there is something wrong with this code or something I may have missed in the server settings that could cause the content length to come back zero after 200 seconds.

最满意答案

听起来很像您的远程API服务器上的超时 - 尝试手动访问它,例如通过浏览器或wget。

Sounds very much like a timeout on your remote API server - try to access it manually e.g. via browser or wget.

更多推荐

本文发布于:2023-08-06 16:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后将   长度   内容   PHP   Apache

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!