max_requests in PHP-FPM (FastCGI Process Manager) is an important part in making sure that PHP-powered apps work smoothly and quickly, especially on websites or APIs with a lot of traffic. It is one of the most important yet often ignored directives in PHP-FPM.
If you’ve ever had weird issues, slowdowns, or memory leaks that go away after restarting a service, your max_requests setting probably needs to be changed.
It’s important to make sure that your blog, eCommerce site, or web app runs smoothly all the time. One important element of that is fine-tuning PHP-FPM, especially the max_requests directive.
We’ll show you everything you need to know about PHP-FPM’s max_requests in this tutorial, including why it’s important and how to set it up appropriately so that your server runs smoothly and reliably.
What is PHP-FPM?
PHP-FPM stands for PHP FastCGI Process Manager. It is a modern and effective way to handle PHP processes. PHP-FPM runs worker processes in the background that handle incoming PHP requests more faster than launching a new PHP process for each request (which is slow).
What does max_requests mean in PHP-FPM?
The max_requests option tells PHP-FPM how many requests a single child process may handle before it is safely destroyed and restarted.
- It’s a safety mechanism.
- It helps prevent memory leaks or misbehaving scripts from degrading performance over time.
So, when a worker reaches the max_requests limit, it gets recycled, which is like saying, “You’ve done enough for now; let’s give you a break.”
Why is max_requests Important?
You might think, “Why restart a perfectly working process?”
The reason is long-term reliability. Over time, PHP processes can accumulate memory bloat or errors. Restarting them at regular intervals ensures:
- Memory usage stays in check
- Old, faulty processes are cleared out
- Improved uptime and server stability
This is especially helpful for high-traffic websites and applications.
Default Behavior of max_requests
By default, max_requests is set to 0, which indicates that a PHP-FPM worker process will keep operating until it is actively restarted or crashes.
Sounds like risky, right? That’s why most production environments should change this parameter.
When is it time to change max_requests?
You should consider adjusting max_requests when:
- You’re running a high-traffic website
- You observe memory usage increasing over time
- Your server is returning frequent 502/504 errors
- You experience performance degradation during long uptimes
Not all servers are the same, so your ideal number might differ.
How to Check Your Current PHP-FPM Configuration
Before changing anything, let’s check your current setup:
grep max_requests /etc/php/*/fpm/pool.d/*.conf
Or if you’re using ServerAvatar, you can find it in the PHP settings section of your application dashboard under your server dashboard section.
Recommended Values for max_requests
There is no one-size-fits-all number, but here are some general guidelines:
Read Full Article: https://serveravatar.com/php-fpm-max_requests-for-stable-performance/#what-is-php-fpm-0
Top comments (0)