Jump to content

Maximum execution time with php-fpm and Apache


NotionCommotion
 Share

Recommended Posts

When making a request from the browser, I get a 503 Service Unavailable after exactly 60 seconds, however, the I see that PHP is still executing the script.

I first tried the following without success. Curiosity question - What is the difference between these two lines?

 ini_set ('max_execution_time',  (string) $container['maxTime']);
 set_time_limit($container['maxTime']);


 I then tried making the following changes to my default pool /etc/php-fpm.d/www.conf, but still defaults at 60 seconds.  Note that the only reason I added default_socket_timeout is that it is the only item displayed with a value of 60 by phpinfo() and was just hoping.

request_terminate_timeout = 120
;max_execution_time=120 ;results in error
php_value[max_input_time] = 120
php_value[max_execution_time] = 120
php_value[default_socket_timeout] = 120

Any ideas?  Thanks

Link to comment
Share on other sites

Thanks kicken,  I removed all the settings I showed for the pool and just used Apache's Timeout and it worked perfect.

May I ask what if any is the  any difference between using ini_set ('max_execution_time', '120') and set_time_limit(120)?

Also, I have found that some settings must be made by editing the pool while others are set by php.ini and/or php commands such as ini_set() and set_time_limit().  Is there any general categorization which dictates which must be defined where?

 

Link to comment
Share on other sites

On 12/12/2021 at 5:52 AM, NotionCommotion said:

Thanks again kicken,  I thought that php-fpm brought some unique differences but maybe not.

The old school way of running php with apache was to use the mod_php apache module, which makes php a part of apache.  So that was certainly different.  You can think of php-fpm as a "php server" process.  Using it with apache or nginx or any other http proxy means that php-fpm is running separately and being communicated with from the http server via fastcgi.   Fastcgi is a specification that evolved from the original cgi spec, that was the earliest way a web server could be configured to send data to and from an external program.  

php-fpm is a php server that implements fastcgi, so it can be used with any http server or proxy that also supports fastcgi.   One of the obvious things to notice is that the effective user running the php script can be different than the user that the apache process is running as.   It also has some efficiency when compared to mod_php, for reasons I won't go into, but that I did examine in a blog post I made.   One big problem with mod_php is that the apache child processes tend to grow and absorb memory when serving php, and this pool of child processes has to be used for every request, so even if apache is handling a request to return an image or css file, or other static content, the apache child process might be 500mb in terms of memory usage, because previously it had been used to run a php script.  This is a big reason that nginx became popular, as it was always intended to be a high performance proxy, and always used fastcgi.

With that said, when php-fpm runs a php process it still does so using the php configuration.  It does have its own settings to manage fastcgi, so in that way it's got another group of settings that you have to configure, and areas where the communication between apache and php-fpm can have issues, so in that way it's more complicated.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.