On occasion, though, an extension may have a bug that leaks memory or causes other problems over time. If that happens, PHP’s FastCGI settings provide a solution.
A setting in fastcgi.conf,
PHP_FCGI_MAX_REQUESTS determines how many requests a PHP job should handle before ending and restarting. The default of zero (0) means each job will handle an unlimited number of requests. When
PHP_FCGI_MAX_REQUESTS is greater than zero, the job will restart after it receives that number of requests, cleaning up any issues that may have accumulated over time, such as memory leaks in extensions.
SetEnv="PHP_FCGI_MAX_REQUESTS=0" (unlimited number of requests for the job)
SetEnv="PHP_FCGI_MAX_REQUESTS=100" (restart job after 100 requests to that job)
Guidelines for Using PHP_FCGI_MAX_REQUESTS
Here is our advice on when to use
PHP_FCGI_MAX_REQUESTS and what value to use:
- If your problem is solved by restarting the web server, it’s likely that
PHP_FCGI_MAX_REQUESTSwill help, but in a smoother way. It basically causes a slow-motion, undetectable rolling restart of the PHP jobs.
- Choose a number that is high enough not to slow down your site, but low enough to restart a given job before any symptoms of the bug arise. A good starting number to try is 100. A lower number may be appropriate for a site with low volume; higher for high volume.
For more information on PHP FastCGI settings, see “Optimize Your IBM i Web Application Using FastCGI.”