When it comes time to choosing a hosting plan, it’s important you pick one that will best match the demands of your WordPress site. For example, an ecommerce site that gets 50,000 visitors per month is typically going to be a lot more demanding than a blog with the same amount of traffic. This is simply due to the fact that many ecommerce sites are dynamic and have a lot of uncached responses and larger queries.
And that is where PHP workers come into play. Read more below about what PHP workers are and how they are used to speed up processing of requests on your site.
What is a PHP Worker?
PHP workers determine how many simultaneous requests your site can handle at a given time. To put it simply, each uncached request for your website is handled by a PHP Worker.
For example, if you have 4 requests that come to your site at the exact same time and your site has 2 PHP workers, two of those requests will get processed while the other two will have to wait in the queue until the first two have finished processing.
If your site is highly optimized or does not have a lot of PHP code (e.g., a complex theme or a lot of WordPress plugins), then processing each request should happen almost instantly, so even with 2 PHP workers and 4 requests, all four requests would be handled very quickly.
We implement server-level caching so in many cases requests are served lightning fast from cache. However, for sites in which the cache is bypassed or missed, PHP workers become very important as they have to do work for each request. Typically we see a lot of uncached requests on ecommerce and community sites. Therefore, these sites will typically require additional PHP workers to ensure every request is processed without delays and completed successfully.
Result of Not Enough PHP Workers
When PHP workers are already busy on a site, they start to build up a queue. Once you’ve reached your limit of PHP workers, the queue starts to push out older requests which could result in 504 errors or incomplete requests. There are a lot of different things that could cause this, such as a slow uncached request from a plugin that ties up more of your PHP workers. In this case, additional PHP workers per site would help solve this problem, as they allow for multiple requests to execute simultaneously.
Still confused? Think of each PHP worker like a ticket cashier at a stadium. The cashier can only help one person at a time. But if you have multiple ticket cashiers then more people can be helped simultaneously. The problem is when people take a too long asking a lot of questions (slow uncached requests), it delays the other people.
Another common error we see due to the lack of PHP workers is 502 bad gateway errors. These are slightly different than 504 errors because the error occurs after a timeout of 60 seconds in the PHP workers queue.
Estimating Number of PHP Workers
Each of the hosting plans at Kinsta includes a certain number of PHP workers. The number included is based on resource usage we have seen with clients over past couple years. In general, sites with lots of static content – articles, static pages, blog posts – don’t need many PHP workers.
4 PHP workers are usually enough for larger WordPress sites. However, this can vary per site as each one will have its own unique set of third-party plugins, queries, dynamic content, and number of cached vs uncached responses. So in some cases, the more PHP workers the better.
You can use the cache analysis reports in MyKinsta analytics to determine how many total requests are currently serving from the cache vs bypassing it, along with the top cache bypass requests.
Top cache bypasses
If you have any questions regarding how many PHP workers you might need, or you think you might be seeing errors due to the lack of PHP workers, please open a ticket with our support team for assistance.