Running a MySQL intensive PHP script that is failing. Apache log reports this:
[Wed Jan 13 00:20:10 2010] [error] [client xxx.xx.xxx.xxxx] (70007)
The timeou
I tried all suggestions, but my problem was in the php-fpm configuration. I set the following line in my php-fpm configuration file:
request_terminate_timeout = 300s
I suspect I'm getting the same error, updated for a later version of Apache (2.4.16):
[Tue Aug 02 11:49:41.930884 2016] [core:error] [pid 28640] (70007)The timeout specified has expired: [client xxx.xxx.xxx.xxx:xxxxx] AH00574: ap_content_length_filter: apr_bucket_read() failed, referer: https://domain.com/script.php
I was wondering why increasing max_execution_time in php.ini wasn't working.
For me, the fix was simply increasing the Timeout directive in httpd.conf https://httpd.apache.org/docs/2.4/mod/core.html#timeout
Timeout 900
(Or in WHM
-> Apache Configuration
-> Global Configuration
, as the case may be)
This timeout applies to time between IO events. So even though the script was outputting data almost immediately, a long delay in the middle of the script's execution was causing the timeout.
I played around with these resource limits in php.ini to correct the problem.
max_execution_time = 300
max_input_time = 300
memory_limit = -1
First, my solution is only applicable to the Apache Web Server.
I am working on a script meant to act as a csv download script for a report against a very very large db, and I encountered this problem too. Am NOT using php, but instead my script is written in some obscure language called heitml ;-)
The request timeout proble does occur in my scenario like this:
[Wed Sep 19 20:29:01 2012] [warn] [client ::1] Timeout waiting for output from CGI script /var/www/cgi-bin/heitml
[Wed Sep 19 20:29:01 2012] [error] [client ::1] (70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed
And the only serious solution I can currently adapt to is using this official timeout config extension here : mod_reqtimeout. It allows adjustment of timeout params like for example:
Allow 10 seconds to receive the request including the headers and 30 seconds for receiving the request body:
RequestReadTimeout header=10 body=30
Allow at least 10 seconds to receive the request body. If the client sends data, increase the timeout by 1 second for every 1000 bytes received, with no upper limit for the timeout (exept for the limit given indirectly by LimitRequestBody):
RequestReadTimeout body=10,MinRate=1000
Allow at least 10 seconds to receive the request including the headers. If the client sends data, increase the timeout by 1 second for every 500 bytes received. But do not allow more than 30 seconds for the request including the headers:
RequestReadTimeout header=10-30,MinRate=500
Usually, a server should have both header and body timeouts configured. If a common configuration is used for http and https virtual hosts, the timeouts should not be set too low:
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
Am yet to find out whether there's a better solution offered by Apache that doesn't require me to use an this module (assuming it's not installed by default -- though it's included in all versions 2.2.15 and later).
There's also the php max_execution_time directive. Note that the web server's timeout settings may also be limiting your script:
Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.
Actually, this looks like an Apache error, it also effects Python scripts. Have you tried googling it yet?
Note: This answer is duplicated verbatim from a similar question.
Original Answer
I have Apache 2.4.6, but the patch to fix it is provided in Apache >= 2.4.8. The key here is to start your output immediately so that Apache (mod_proxy_fcgi) thinks the connection is active.
For example, I am using PHP and the DB query for my AJAX call takes > 30 seconds. Because I know that the overall response will be "Content-Type: application/json", I send that header immediately.
#1: Start output immediately
#Note: Sending the header is innocuous
# it can be changed later using the $replace parameter
# (see #3)
header( 'Content-Type: application/json' );
#2: Run slow query
mysql_query( "SELECT * FROM giant_table" );
#3: Change header as needed
header( 'Content-Type: application/csv', true );
#output content