Php – Apache2 Proxy timeout

apache-2.2httpd.confmod-proxyPHPphp-fpm

I have Apache2 with PHP + PHP-FPM configured according to:

http://wiki.apache.org/httpd/PHP-FPM

I am writing a script that will take a long time to execute on an internal Vhost, but keep getting timed out, everything runs flawlessly if the script executes in under 30 seconds.

My apache log tells me:

[Wed Apr 17 21:57:23.075175 2013] [proxy_fcgi:error] [pid 9263:tid 140530454267648] (70007)The timeout specified has expired: [client 58.169.202.172:49017] AH01075: Error dispatching request to :, referer:

When trying to run the script I am given a 503 Service Unavailable after exactly 30 seconds of execution time. Logically this would mean I have a timeout directive or setting set to 30 seconds, but I have these in my Vhost's config:

Timeout 600
<IfModule proxy_module>
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9001/home/pyrokinetiq/scripts/$1 timeout=600
    ProxyTimeout 600
</IfModule>

(php-fpm is running on port 9001 for me)

I have also tried placing the Timeout and ProxyTimeout in httpd.conf with no difference.

It seems there's another timeout setting somewhere that's specific to mod_proxy_fcgi, but I can't find it. I installed the Apache2 httpd from the official tarball, none of the mods seem to have come with any configuration files.

If anyone can point me in the right direction it would be much appreciated.

Best Answer

I finally fixed this problem after testing several configuration parameters. I tested the solution twice, removing all previous changes. Only one parameter was needed for me to fix it.

For the latest versions of httpd and mod_proxy_fcgi you can simply add timeout= to the end of the ProxyPassMatch line, e.g.:

ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1 timeout=1800

For older versions it was a little more complicated, e.g.:

<Proxy fcgi://127.0.0.1:9000>
  ProxySet timeout=1800
</Proxy>
ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1

I needed to add the Proxy directive to set the timeout to 30 minutes. In some applications, usually when operating database, there are routines that can take more than 10 minutes to execute. I temporary set the timeout to 30 minutes to ensure they finish. Specifically useful when using the installation wizard, which takes too much time (in my humble opinion).

By the way the intial input that helped me to solve this issue was found in the following URL address.

Related Topic