I am having trouble getting Timeout directive to work, I have reproduced the issue in the below instructions and official Docker container. The server is using the standard MPM prefork model with default configs. My understanding is that the Timeout should return a 500 error after the timeout or some sort of 4xx or 5xx response code but it doesn't. Is my understanding incorrect?


mkdir /tmp/test; cd /tmp/test
echo "<?php sleep(10);" > index.php
docker run -d -p 80:80 --name apache-php -v "/tmp/test":/var/www/html php:5.6-apache
time curl http://localhost/ # should take 10 seconds

Now, lower timeout to 1 second:

docker cp apache-php:/etc/apache2/apache2.conf . # Copy to host, since container doesn't have editor.  
echo "Timeout 1" >> apache2.conf # Set Timeout to 1, default is 300.  
docker cp apache2.conf apache-php:/etc/apache2/apache2.conf # Copy conf file back to container  
docker exec -it apache-php /bin/bash
service apache2 reload
exit # exit docker container. 

Test for error:

time curl http://localhost/ # Here is where I expect a timeout error, but it works just the same as before and takes 10 seconds.

p.s. I have read that AcceptFilter can affect things until the request gets past it. We do have the below config as well:

AcceptFilter http none
AcceptFilter https none
  • 1
    you are using the mod_php third party module which can probably override this value for php content, I would start checking its defaults or use a more sane and up to date method which does not involve using mod_php at all. – ezra-s Mar 28 '18 at 8:36
  • Thanks, we have php-fpm on our roadmap. I would have thought the default implementation of PHP and Apache would respect the Timeout or at least mentioned edge cases in the docs. – Elijah Lynn Mar 29 '18 at 20:55

Apache Timeout refers to TCP timeout, not script execution time. PHP timeouts are controlled via two directives located in php.ini:

From php.net

max_input_time = integer

This sets the maximum time in seconds a script is allowed to parse input   
data, like POST and GET. Timing begins at the moment PHP is invoked at the
server and ends when execution begins. The default setting is -1, which means      
that max_execution_time is used instead. Set to 0 to allow unlimited time.

And (this is probably the one you need)

max_execution_time = integer

This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server.    
The default setting is 30. When running PHP from the command line the default setting is 0.   
The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.   
You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.   
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.   
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.