PHP workers are background processes that run on your server and that execute PHP code.
In WordPress, whenever Nginx receives a request that needs to be processed by PHP, it will forward the request to PHP-FPM, which will assign the request to an available PHP worker.
PHP workers are responsible for building pages, processing scheduled tasks, and handling any other PHP-related functions on your site.
The Impact of PHP Workers on Performance
PHP workers impact WordPress performance in two ways:
- They determine how many simultaneous un-cached requests your site can handle at any given time. If your site receives more requests than the number of PHP workers, some requests will have to wait in a queue until a worker becomes free. This can result in slow loading times or timeouts for your visitors.
- They affect the CPU and memory usage of your server. Each PHP worker consumes a certain amount of CPU and memory resources, depending on the complexity of the PHP code and the size of the data being processed.
Let’s understand this with the help of an example —
PHP workers are like cashiers in a supermarket. They process the requests of the customers (visitors) who want to buy something (view a page). The more cashiers (PHP workers) there are, the faster the customers can be served, and the less time they have to wait in line (queue).
However, having too many cashiers (PHP workers) can also be inefficient and costly, as they may not have enough space (server resources) or customers (requests) to justify their presence.
Therefore, it is important to find the optimal number of cashiers (PHP workers) for your supermarket (WordPress site), depending on the size, layout, and demand of your store (site).
If your site has too many or too few PHP workers, you’ll either have performance issues or waste server resources. As such, it is important to try to keep your site as efficient as possible. This allows you to reduce the number of PHP workers needed.
Depending on your site’s needs and traffic patterns, the degree to which this is possible varies, of course. Some ways you can do this are by:
- Taking advantage of caching, and optimizing your web apps to ensure your codebase is running as efficiently as possible.
- Minimizing the amount of PHP code and the number of database queries.
- Monitoring your server’s CPU and memory usage using those as an indicator as to when would be a suitable time to scale a server up to account for an expected increase in traffic.