Increase PHP-FPM idle timeout setting

耗尽温柔 提交于 2019-11-30 13:08:02

I have found my self in similar situation with long running processes and php-fpm and fastcgi when migrated from mod_php.

The error you are seeing is from apache's fastcgi proxy who killed connection to php-fpm pool because your script did not outputted anything for 30 seconds.

You can change idle-timeout in your apache config to extend it (cannot be 0):

FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /run/php/php7.0-fpm.sock -idle-timeout 1800 -pass-header Authorization

Chain goes like this: Apache -> FastCgiExternalServer proxy -> php-fpm pool server -> php process

Apache proxy kills connection to php, so setting max_execution_time or set_time_limit from php doesn't matter.

AFAIK if php is being run on Apache via mod_fastcgi, there is no way to set per script time limits from php code or .user.ini or via apache (.htaccess). So that means that by extending it in one place you are extending timeout for eg. both your frontend and backend users. Alternatively you could separate it via 2 vhosts and define different timeout values there.

While this doesn't necessarily fit the OP's configuration, most people are going to be running PHP-FPM under a proxy setting. As such, you can set the timeout for a proxy setup like so (this is my php.conf)

<Proxy "fcgi://127.0.0.1:9000">
   ProxySet timeout=300
</Proxy>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
    SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

If you're using a .sock file instead, just replace both instances of fcgi://127.0.0.1:9000 with the command to use the sock file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!