Running a WordPress site smoothly and efficiently involves understanding technical elements- like PHP memory limits and PHP workers. But what exactly do these terms mean, and how do they impact your WordPress site’s performance?

Think of your WordPress site as a bustling coffee shop. The PHP memory limit is like the storage space for coffee beans, milk, and other ingredients. If the storage is too small, your baristas (PHP processes) will struggle to make drinks efficiently because they keep running out of supplies. On the other hand, PHP workers are like the baristas you have on staff. More baristas mean more drinks can be prepared simultaneously, reducing customer wait times.

This article explains the PHP memory limit and PHP workers, when to adjust them for optimal performance, and how to do this on Kinstas servers.

What is a PHP memory limit?

Every time your site loads a page activates a plugin or uses a theme feature, PHP scripts execute, and they need memory to function properly. The PHP memory limit determines how much memory your WordPress site has access to.

You’ll want a PHP memory limit high enough that your site can handle all its tasks without running into issues like:

  • Slow page loads — Not enough memory can slow the execution of PHP scripts, leading to longer page load times.
  • Plugin failures — Resource-intensive plugins may not function correctly if they don’t have enough memory.
  • White screen of death — When a PHP script runs out of memory, your site may display a blank white screen instead of loading properly.

What are PHP workers?

PHP workers are another crucial component that impacts your WordPress site’s performance. Workers are background processes on a server that manage the execution of the PHP code that powers your site.

In WordPress, these workers are responsible for building pages, processing scheduled tasks, and more. They also generate HTML pages to serve your site’s visitors and determine how many simultaneous uncached requests your site can handle at any given time.

When a visitor accesses your WordPress site, a request is sent to the server, which is then processed by a PHP Worker. Several requests can be processed simultaneously if your site has multiple PHP workers. For instance, if your site has two PHP Workers and five requests come in simultaneously, two will be processed immediately, while the other three will wait in the queue until the first two have been completed.

This queuing system helps manage traffic, but it also means that insufficient PHP Workers can lead to delays and slower response times when multiple requests are made at once.

Managing PHP memory limits

Kinsta’s default PHP memory limit is 256MB, which is more than enough for most WordPress plugins and sites.

It’s also important to know that if you set the limit too high, a misconfigured or broken script can cause serious issues when using too much memory.

When to increase PHP memory limit

Increasing the PHP memory limit could be essential for maintaining the performance and stability of your WordPress site when dealing with resource-intensive tasks.

The most common signs that your PHP memory limit needs to be increased is when you encounter error messages like “Allowed memory size exhausted.” This indicates that the current memory limit is insufficient for executing tasks.

Here is an example of what the error message may look like:

PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)

This message means that the PHP script attempted to allocate more memory than the allowed 256MB (268,435,456 bytes), resulting in a memory exhaustion error. The script tried to allocate an additional 20KB (20,480 bytes) but ran out of memory.

If your site is hosted on Kinsta, these memory exhaustion errors are logged automatically. You can check for these errors on the MyKinsta dashboard. Navigate to your site and select the Logs tab.

WordPress site's MyKinsta error log
WordPress site’s MyKinsta error log.

Look for entries that include “PHP Fatal error” and “Allowed memory size exhausted.” These logs will indicate the exact memory limit exceeded and the additional memory the script attempted to allocate.

By monitoring these logs, you can identify if your site frequently hits the PHP memory limit and decide whether to increase the memory allocation to ensure smooth script execution.

How to increase your site’s PHP memory limit

When a site’s PHP memory limit needs to be increased, Kinsta customers can purchase a PHP memory limit add-on.

This add-on increases the memory limit from 256MB to 512MB for $50 per site per month.

To purchase this add-on, please get in touch with the Account Management team via the live chat in MyKinsta dashboard or e-mail us at [email protected].

Managing PHP workers

PHP workers are particularly important for sites that do not cache a lot of their content. The more dynamic a site is, the more PHP workers it will need. Cached content doesn’t require PHP workers; it is only necessary when the site queries the database to get or change information or when it needs to execute other PHP scripts.

This means effective caching can significantly reduce the workload on PHP workers by serving cached content instead of generating it dynamically for each request.

At Kinsta, we prioritize your site’s performance by implementing various technologies to maximize PHP performance. We offer page caching at CDN and server levels, utilize premium servers (C2 and C3D virtual machines) equipped with Google Cloud’s fastest CPUs, and ensure a highly optimized MySQL server hosted locally to reduce network latency and improve data retrieval and processing speeds.

When to add more PHP workers

The number of PHP workers needed depends on several factors, including its reliance on database queries, code optimization, and the type of traffic it receives.

An optimized site with efficient PHP code and database queries will process requests quickly, freeing up PHP workers for the next request.

Dynamic sites like ecommerce stores, forums, learning sites, and membership sites typically require more PHP workers than static, brochure-type sites. Additionally, busier sites usually need more PHP workers to handle increased traffic.

Adding more PHP workers can help manage increased traffic and reduce wait times for processing requests, but it’s essential to balance this with available CPU and RAM resources. If the server does not have enough CPU and RAM to support additional PHP workers, it can create a bottleneck, leading to performance issues.

With Kinsta, you can monitor PHP worker activity using Kinsta’s APM tool to identify performance issues and slow queries.

Kinsta APM tool in MyKinsta
Kinsta APM tool in MyKinsta.

If your site frequently reaches its PHP worker limit, you may need to add more PHP workers or optimize your site’s code and queries to improve performance.

How to add more PHP workers

To add more PHP workers to your site, you can upgrade your hosting plan or purchase additional PHP workers. Here’s how you can do it:

  • Upgrade your hosting plan — Each Kinsta plan has a specific number of PHP workers. Upgrading to a higher-tier plan increases your site’s number of PHP workers. For example, moving from a starter to a business plan will increase your PHP workers from two to four.
  • Custom plans — For sites with specific needs, Kinsta offers custom plans where you can specify the number of PHP workers required. This is ideal for high-traffic sites or sites with significant dynamic content. Contact the Kinsta sales team to discuss your requirements and get a custom quote.

By increasing the number of PHP workers, you can help your site handle more simultaneous requests, leading to better performance and a smoother user experience.

However, always ensure that your server has enough CPU and RAM resources to support the additional PHP workers to avoid creating performance bottlenecks.

Best practices for PHP resource management

Effective management of PHP resources is crucial for maintaining the performance and stability of your WordPress site.

Here are some best practices to optimize your PHP memory and worker usage:

  1. Efficient caching — Implementing robust caching mechanisms can significantly reduce the load on PHP workers. By serving cached content to visitors, you minimize the number of requests that need to be processed by PHP workers, freeing them up for more dynamic tasks.
  2. Optimize code and queries — Ensure your PHP code and database queries are well-optimized. Efficient code execution and streamlined database interactions reduce processing time, allowing PHP workers to handle more requests in less time.
  3. Upgrade PHP versions — Regularly update to the latest PHP versions, often including performance enhancements and security improvements. Newer versions of PHP are typically faster and more efficient.
  4. Monitor resource usage — Use tools like Kinsta’s APM or Query Monitor to evaluate resource usage. Monitoring helps identify bottlenecks and inefficiencies in real-time, allowing you to take corrective action promptly.

Summary

Managing PHP resources effectively is crucial for the performance and stability of WordPress sites hosted on Kinsta. This article has explored PHP memory limits and PHP workers, their roles, and how to optimize their usage.

For personalized recommendations or to increase your PHP memory limit or PHP workers, please open a new ticket or email [email protected].

Joel Olawanle Kinsta

Joel is a Frontend developer working at Kinsta as a Technical Editor. He is a passionate teacher with love for open source and has written over 200 technical articles majorly around JavaScript and it's frameworks.