Make Apache wait longer before delivering HTTP 408 request timeout - php

My configuration:
Apache 2.2.4
PHP 5.2.4 (fastCGI)
Windows XP pro
I have a script that takes more than a minute to run but after exactly 60 seconds (proven by Fiddler) the server always delivers a 408 timeout. My PHP max execution time is set to 120 seconds. After doing some reading I've tried putting a "Timeout 120" directive in my Apache config file though I'm not confident that directive relates to what I'm trying to do. No dice. Is there any way to make apache wait longer before returning the 408? (Yes, I've restarted the web server between making config changes). Many thanks for any guidance.

Try setting the -appConnTimeout parameter in the FastCgiServer directive.

I am not sure which one of these lines solves the problem; probalby the execution time - but it solved my 408 problems (added to settings.php):
$conf['drupal_http_request_fails'] = FALSE;
ini_set('max_execution_time', '600');
ini_set('memory_limit', '512M');
ini_set('upload_max_filesize', '128M');
ini_set('post_max_size', '128M');
ini_set('query_cache_size', '128M');

Related

503 timeout on PHP 5.6.31

I have two and more servers running PHP 5.4.45 with same scripts and none of them are doing any issue when calling a script that requires more than 60 seconds to finish.
However, a new server having PHP 5.6.31 is returning 503 timeout, when I run the same script. I tried everything found on the internet from keepAlive to timeout in httpd.conf and in php.ini, I already have
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 5);
Inside the code and all that. Same script same everything just different PHP version on 5.4.45 it works perfectly while on 5.6.31 I always get timeout unless when the full script executes in less than 60 seconds [I don't know where that limit comes from eventhough I changed anything related to 60 from the httpd.conf and php.ini) .
Kindly can you help me troubleshoot.

Internal Server Error (500) and PHP max_execution_time on Linux server

I have a php script that need to be processed for one to 5 hours (sending newsletters to our customers). I tried both set_time_limit(2000); and ini_set('max_execution_time', 360000); but neither works. They work perfectly on the XAMPP local server, but they do not work on our dedicated server (Unix & Apache). I also changed the Apache timeout to 300 (which was 50), yet after 30 seconds of script running, it returns this:
Internal Server Error Page (Error 500)
I have no idea if there is any other place for timeout and/or why the server does not honor the ini_set() or set_time_limit() functions. We are using Unix CentOS 6 and Plesk 11.9 as server. I also changed the default php.ini max_execution_time, and it works...
I read many articles and forums, yet I don't know why this happens. I appreciate your help.
// add, in your php file header or config
ini_set('max_execution_time','256'); //max_execution_time','0' <- unlimited time
ini_set('memory_limit','512M');
Good work!
a better way would be using ini_set() or set_time_limit() at the top of the script which sends newsletters to the customers...you should not try to main config files...and also, as someone suggested above, cron jobs are good fit for such situations..
I appreciate your answers and comments. I setup the cron job, and it works perfect. I also have tried the chunk-chunk (150 emails per chunk) approach, and that one works too.
If you using Vps:
Edit your php.ini file:
max_execution_time = 256
memory_limit = 512M
Then, run command line to restart apache
service httpd restart
Or header file
ini_set('max_execution_time','256');
ini_set('memory_limit','512M');
Good luck!

Apache and or PHP Timeouts - Stumped.

I have a PHP script that when called via a browser it times-out after exactly 60 seconds. I have modified httpd.conf and set the Timeout directive to be 300. I have modified all PHP timeout settings to extend longer than 60 seconds. When I run the script from the command line it will complete. When I execute through browser each time after 60 seconds, POOF, timeout.
I have also checked for the existence of timeout directives in any of the .htaccess files. Nothing there.. I am completely stumped.
I am also forcing set_time_limit(0) within the PHP code.
I've been digging and testing for a week and have exhausted my knowledge. Any help is greatly appreciated.
You need to make sure you are setting a higher timeout limit both in PHP and in Apache.
If you set a high max_execution_time in php.ini your script won't timeout, however, if you are not flushing the output butter of the script's results to the browser on a regular basis, the script might time out on the Apache end due to a network timeout.
In httpd.conf do:
Timeout 216000
In php.ini do:
max_execution_time = 0
(setting it to 0 makes it never time out, like with a CLI (command line) script).
Make sure you restart Apache after you are done! On most linux distro's you can do this by issuing the command (as root):
service httpd restart
Hope this helps!
There are numerous places that the maxtime can be set. If you are using FastCGI, especially though something such as Virtualmin, there are an additional set of settings for max_execution_time that are hidden to you unless you have access.
In short, you will need to figure out all the places, given your PHP stack setup, there can be an execution time limiter, up those values, restart the server, and then do
set_time_limit(0);
for good measure.
Without more information about your specific setup and given my experience in dealing with execution time hangups in PHP, that's the most I can tell you.

exec from php is causing an "Premature end of script headers: php-cgi.exe" error

I have a php script written which calls an external command using exec which compiles a spacial database query result into a shape file. In tables with lots of records (say 15,000), this command can take as long as 7 minutes to execute. The script works fine on scripts which do not take too long (maybe <2min) but on longer scripts (like the 7 minute one) the page will display "500 internal server error". Upon reviewing the Apache server log, the error states: "Premature end of script headers: php-cgi.exe". I have already adjusted the php maximum execution time to allow more than enough time, so I know it is not this. Is there an Apache maximum that's being hit, or something else?
Premature end of script headers means that webserver's timeout for CGI scripts was exceeded by your script. This is a webserver timeout and it has nothing to do with php.ini configuration. You need to look at your CGI handler configuration to increase time allowed for CGI scripts to run.
E.g. if you are using mod_fastcgi you may want to specify the following option in your Apache config: FastCgiServer -idle-timeout 600 which will give you timeout of 10 minutes. By default fastcgi provides 30 seconds. You could find some other fastcgi options here http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
Apparently, the default httpd.conf file included in Apache 2.4 doesn't automatically include the extra file httpd-default.conf under /conf/extra (probably by design), which includes the timeout parameter. Since the timeout parameter isn't defined, it reverts back to the default value of 30 seconds, and your script(s) time out.
I did the following to resolve it:
Opened httpd.conf and added the following line to the bottom:
Include conf/extra/httpd-default.conf
Restarted Apache, and it worked.
An alternative would be to simply add the following line(s) to the httpd.conf file:
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
Hope this helps someone out there :)

Php's set_time_limit throws a 500 error?

When I use set_time_limit and the script runs for any amount of time greater than 360 seconds, it throws a 500 error.
359, nothing, 360 and above, error.
I don't have access to php.ini, how can I fix this bug?
script runs for any amount of time greater than 360 seconds, it throws a 500 error.
It sounds like you're hitting another timeout somewhere. If your server uses FastCGI, for example, Apache and/or the FastCGI process could be configured to only wait for six minutes (360 seconds) before timing out. It also could be that there's a reverse proxy sitting between you and Apache with the same timeout, though proxy timeouts are usually 504s, not 500s.
Please examine your server configuration. If you're on shared hosting, ask your host about the timeout.
If your script needs to execute for an extended time, you may wish to find another way to run it.
If you use Apache you can change maximum execution time by .htaccess with this line
php_value max_execution_time 200

Categories