Contents
- Start with the cause, not by automatically adding workers
- Measure the queue and type of actual work
- Worker memory is not just PHP memory_limit
- The number of processes is related to the service time
- OPcache does not store the result of any function
- Cache must maintain security and content contract
- Controlled change and verification
- Frequently asked questions
Start with the cause, not by automatically adding workers
PHP-FPM can be overloaded by long CPU jobs, database waits, disk, external services, or lack of free processes. These situations require a different solution. A higher pm.max_children will only help some of them and may also increase memory or database pressure. First, correlate the queue, request time, and actual resource consumed.
In the CH-J audit of November 28, 2026, a significant portion of the CPU was consumed by repeated physical verification of the publish files with each PHP request. The presence of OPcache alone did not eliminate this data work. Therefore, the optimization began by changing the location of the expensive check in the publish chain, not by increasing the number of processes across the board.
Measure the queue and type of actual work
Monitor active and idle processes, listen queue, max children reached and slow requests in FPM status. Restrict access to detailed status to authorized administration. At the same time, read upstream time in NGINX and corresponding application diagnostics. High client network response alone does not prove that PHP spent the same amount of time on the CPU.
Distinguish between the current state of the problem and the historical maximum. One overrun over a long period is not the same as a persistent queue. For slow requests, identify the specific URL and stage, but protect personal information and login secrets. Slowlog can reveal the function, while an external profiler can help determine the cost of individual calls.
Worker memory is not just PHP memory_limit
memory_limit limits a specific memory area of a PHP request; it is not the full resident size of the process. RSS includes shared pages, so simply multiplying the RSS maximum by the number of workers may overestimate memory. PSS and observing the entire pool give a more useful picture in the appropriate environment. Include system, database, cache, and reserve.
To estimate, set a reasonable memory budget and measure a representative workload, including demanding endpoints. An average of several light requests will not protect against large exports or document generation. Too high a worker limit can cause swapping or OOM and degrade availability at times of increased traffic.
The number of processes is related to the service time
For guidance, the required concurrent service is related to the intensity of arrivals and the time the worker holds the request. This is an average steady-state model, not a guarantee for peaks. Furthermore, CPU-bound work cannot speed up indefinitely by adding processes to the same cores.
The choice of static, dynamic or ondemand depends on the type of traffic, startup costs and memory reserve. Also set reasonable wait and process lifecycle according to the actual problems. A long timeout will not eliminate the cause of the blocked backend; it can only extend the time for which unfinished requests occupy capacity.
OPcache does not store the result of any function
OPcache helps to avoid repeated parsing and compilation of PHP code. However, it does not automatically cache every query to the database or the hash file. In our isolated before/after test on the same 6vCPU VM, the median CPU of the actual PHP homepage dropped from 205.732 ms to 6.247 ms after changing the authentication path.
The measurement included 40 requests in each variant at a controlled frequency of 4 per second. This is not the long-term performance of production mirrors or their maximum RPS. The result demonstrates specific work removed for the same input. It cannot be deduced from it that increasing OPcache or overriding FPM parameters will bring the same savings to every website.
Cache must maintain security and content contract
If you move validation outside the request, define the validity of the result, the binding to an immutable revision, and the behavior on error. For CH-J, full validation is tied to publication and managed local checks. There must be no cache that accepts changed files without warning or makes old expected values lose their meaning.
A flat HTML cache requires separate consideration of session, authentication, CSRF, and personalization. A page with private content cannot be accelerated by publishing it to other clients. Even with proper CPU work removal, verify error conditions, publication of a new version, and rollback. A fast but content-incorrect result is not successful optimization.
Controlled change and verification
- You have the default metrics and the exact symptom.
- The selected change corresponds to a CPU, memory, or wait cause.
- The test uses the same inputs and comparable traffic.
- You monitor response, queue, errors, and memory consumption.
- The configuration has a verified return and the content remains correct.
After one change, reassess the original symptom. If the queue disappeared after removing the unnecessary feature, further worker augmentation may not be necessary. Good tuning results in a concrete explanation of the improvement and a known operational margin, not a long list of modified directives without measurement.
Frequently asked questions
Will increasing max_children solve the high CPU?
CPU bound work will not eliminate itself and can worsen process contention.
Is memory_limit the entire RAM of the worker?
No. The process also includes other and shared parts of memory.
Does OPcache eliminate repeated hashing of files?
Not automatically. Bytecode caching and application data work are different things.