Apache php fpm timeout

How do I set timeout when using Apache and PHP-FPM via SetHandler?

Remi’s RPM repository — Forum → User support → How do I set timeout when using Apache and PHP-FPM via SetHandler?

You must login or register to post a reply

Posts: 9

1 Topic by ldennison 2015-07-20 22:59:10

Topic: How do I set timeout when using Apache and PHP-FPM via SetHandler?

Following the instructions at http://blog.famillecollet.com/post/2014 … mprovement , I have configured my Apache/PHP-FPM installation like this, where example.com is the domain for the site and each site has its own PHP-FPM process, and this code is in a VirtualHost for the site being represented:

 SetHandler "proxy:unix:/var/run/php-fpm/example.com.sock|fcgi://localhost" 

That works fantastic. It doesn’t have all this issues of ProxyPassMatch. However, I recently encountered the situation where I need to set a higher timeout for Apache. I have a script that takes a few minutes to execute, and I want to enable that without getting a 503 Timeout/Service Unavailable. Currently, Apache sends a 503 after 30 seconds. I have confirmed that it is not PHP-FPM that is terminating the request (PHP continues to execute the request in the background).

I did some research and tried all of the following methods. None of the have worked. Apache still sends a 503 response after 30 seconds with each of these different «solutions».

 SetHandler "proxy:unix:/var/run/php-fpm/example.com.sock|fcgi://localhost timeout=300" 
 ProxySet timeout=300 SetHandler "proxy:unix:/var/run/php-fpm/example.com.sock|fcgi://localhost" 
TimeOut 300 ProxyTimeout 300 SetHandler "proxy:unix:/var/run/php-fpm/example.com.sock|fcgi://localhost" 

Do you have any proposed solution to this problem? I’d really like to keep using SetHandler instead of reverting back to ProxyPassMatch.

Читайте также:  Java map iterator пример

Источник

How to increase PHP timeout values in Apache and NGNIX

There comes a time when you really need to increase the amount of time it takes before your server stops a particular PHP process from continuing. This is called PHP session “timeout”.

Under normal conditions you want to keep these values low so your connections are as efficient as possible. These limits are also in place to prevent poorly written scripts from monopolizing too many resources on your server.

However, there’s plenty of reasons you would want to increase these values – usually temporarily.

Reasons may include:

  • long import processes (e.g. one-time or initial loads of data)
  • lengthy upgrade processes that need to finish or doom your application to a broken status
  • ridiculous AJAX functions with limited or no error handling
  • processing of feeds or other data where the scripts are too dumb to stop and take a break
  • you crave instability in your life

Regardless of your need, there’s a hierarchy of places where you have to make these adjustments.

Changing PHP Timeouts in APACHE DSO

Starting with Apache, you first have to determine which PHP handler you are working with. Under DSO – your server PHP.ini file is going to be where you can manipulate this value.

Find the following values:

max_input_time = 120

&

max_execution_time = 120

The value “max_input_time” controls the total time a PHP script will spend on parsing input data. If this value is not present, then PHP should default to 60 seconds. You can increase this value as much as you want – however – understand that exceedingly high values will tie up resources like you wouldn’t believe.

“max_input_time” is the time spent prior to starting the “max_execution_time” on a PHP script.

“max_execution_time” is the total amount of time that a PHP script is allowed to process. When you set this higher, it allows all scripts to run as long as the value in seconds you place here.

If you can not set additional limits in your application itself – this should be the only place you need to make changes to PHP.ini under DSO.

How to find the path to your PHP.ini file

Finding the path is not always as easy as you would think. Some servers wind up a bit messy and multiple php.ini files exist. To find yours in the fastest way possible open up an SSH prompt and type the following:

This command outputs out of the PHP configuration values and information much like the phpinfo(); command would produce. You can find the path to your php.ini file buried in this output. You may want to just grep the information with the following command:

You should see an output that looks something like this:

Configuration File (php.ini) Path => /usr/local/lib/php.ini

Changing PHP Timeouts under suPHP / FastCGI

suPHP is a PHP handler that forces each process to run under the account owner of that process. It is done for better security across virtual hosts and is the most common configuration in any multi-domain or shared hosting environment. FastCGI is a similiar PHP handler and handles changes to php.ini in the same manner.

What is unique about suPHP is that each individual domain or vhost can have its own PHP.ini files that further refines changes and adjustments in your PHP configuration. Note – you only have to add you changes to this file that you want overridden or changed. The server will default to the server’s PHP.ini for all functions not specified in the PHP.ini file.

Changing PHP Timeouts in NGNIX

Changes to PHP values in NGNIX are handled a little different. You first find your php.ini file and make the same changes to input and execution times as described above.

Changes in PHP-FPM

If you are using PHP-FPM (Fast Process Manager) you need to navigate to :

Changes in your NGINX Config

One last place to change.. and you need to do this for each site you want to make the increase on.

Find the lines for each domain in your site-available file.

/etc/nginx/sites-available/some-domain-you-want-to-change.com
location ~ \.php$ include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_read_timeout 300;
>

To increase the timeout values for all sites globally you need to edit your main nginx.conf file.

Find the values between the http brackets

You then need to restart/reload PHP-FPM & Nginx to make the changes active.

service nginx reload
service php5-fpm reload

Changes in your Apache Config

If you are using Apache, you need to go into your httpd.conf file and locate:

Timeout 600 (or whatever the value is currently set at) and increase this as much as you desire.

That’s it ..

Источник

Оцените статью