In this blog post, we’ll talk about PHP workers, what they are, what they do, how caching helps, and how many you need for your WordPress site or store.
Many blog posts talk about the technical side, but we’ll try to make it really easy to understand, and we’ll do it with a fun analogy.
A PHP worker is like a take-out counter clerk
Think of a PHP worker as a take-out counter clerk. You go to the counter and give the clerk the order of three pizzas, two burgers, and five beers. They need to go pick up each item from the kitchen and fridge, pack it, tell you the bill amount, take your cash, put it in the cash drawer… you get the point.
This is what PHP workers do for your website, for each visitor that comes to your store. The PHP worker requests HTML, CSS, scripts, images, products, and content from the database, and everything else for the visitor to be shown the entire page. Of course, they do these things a lot faster than a regular clerk.
But there can be complications or delays at the counter. In some cases, the pizza might not be ready, and they’ll have to wait for the pizzaiolo (the person making the pizza) to finish it. In other cases, they might have a partnership with a burger shop, and they need to get your veggie burger from them.
For a PHP worker, waiting for the pizzaiolo might be waiting for a slow response from the database (because a plugin is doing direct queries into it). Waiting for the burger shop could be an API request to an external server, like payment gateway or inventory management.
Let’s complicate this analogy a bit more. Because the take-out owner wanted the best in the latest tech, you can now only order your food from a display. But because the user experience is not that great, it’s hard to navigate, and it takes a long time for you to finish your order. But it’s a cool way to order food!
Unfortunately, the queues became unbearable quickly, so they had to revert to the old way of doing things.
In the case of a PHP worker, this would be a complicated theme and page builder that require a lot of resources to show you a magnificent design.
Why can’t I just have unlimited (PHP) workers?
For the same reason you can’t put 20 counters in a small shop. Each counter needs its own space to process your order efficiently.
Each PHP worker requires CPU and memory resources to process requests. And the same as a person takes space just doing nothing, PHP worker needs resources to be available for processing requests, and then further resources to actually start and finish its job.
This means that if you want to increase workers, you’ll need to give them more space, which for PHP workers means more CPU and memory resources (more powerful server).
How does caching help
In our take-out example, caching would be a regular customer always ordering the same thing. The clerk gets the order in advance, already paid, and can prepare everything for the customer when they come to the counter. This is a lot faster for the customer.
For websites, caching serves pre-saved site data and can lower the time PHP worker needs to process a request or even completely bypass it. Commonly, this is the HTML code of every page that is served cached if the user does not have a cookie (like for cart or checkout).
How to use fewer PHP workers?
We’re really beating the analogy to death now, but you can do three basic things:
- “Smaller food menu“: do less on your store. This means fewer plugins and no complex features, like conditional discounts requiring multiple requests into the database or filtering plugins that do the same.
- “Simplify your order process“: simplify your store design, use a simple theme and page builder, resize, optimize and compress images. The smaller the page size, the faster the PHP worker can process it.
- “Increase your shop size“: if all else fails, upgrade your hosting plan. This will give you more resources for new and larger PHP workers, which can process more and larger requests.
Often, you might have just one plugin that’s constantly delaying the process. Have a developer look into your site to see if something is using up all PHP workers.
This optimization makes sense only up to a certain degree. Once you have a successful store, processing tens or hundreds of orders per day, don’t be cheap – upgrade your server, and focus on growing your store.
I hope we made PHP workers understandable, even if you haven’t read about them before.
If you’re looking for a hosting that understands exactly how your “take-out shop” works, have a look at WooCart, the first hosting built exclusively for WooCommerce.