Running a WordPress site smoothly and efficiently involves understanding technical elements- like PHP memory limits and PHP threads. 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 threads are like the baristas you have on staff. More baristas mean more drinks can be prepared simultaneously, reducing customer wait times.

To make managing these limits easier, Kinsta provides real-time insights in the Info tab of each site’s dashboard. Here, you can see exactly how often your site has hit the PHP memory or PHP thread limit, helping you identify potential performance issues before they impact your users.

View the PHP performance of your site on MyKinsta
View the PHP performance of your site on MyKinsta.

This article explains the PHP memory limit and PHP threads, 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 threads?

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

In WordPress, these threads 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 thread. Several requests can be processed simultaneously if your site has multiple PHP threads. For instance, if your site has two PHP threads 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 threads 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.

You can also track how often your site has reached the PHP memory limit over time in Analytics > Performance. Scroll down to the PHP Memory Limit Reached section to view the relevant data.

PHP memory limit reached chart
PHP memory limit reached chart.

By monitoring this chart and the accompanying logs, you can determine if your site frequently hits the memory limit. If so, increasing the memory allocation can help prevent issues and ensure smooth script execution.

How to increase your site’s PHP memory limit

If your site’s PHP memory limit needs to be increased, Kinsta offers a PHP Memory Add-on that raises the limit from 256MB to 512MB for $50 per site per month.

You can purchase this add-on directly from the Add-ons page in MyKinsta. Just go to WordPress Sites > [Your Site Name] > Add-ons, scroll down to PHP Memory, and click the Change button. This will open a modal where you can proceed with the request.

PHP Memory Add-on
PHP Memory Add-on.

To complete the purchase, click the Open Chat button in the modal to start a conversation with our Account Management team via live chat.

PHP memory limit chat with account manager
PHP Memory limit chat with account manager.

You can also reach them via email at accountmanagement@kinsta.com.

Managing PHP threads

PHP threads are particularly important for sites that do not cache a lot of their content. The more dynamic a site is, the more PHP threads it will need. Cached content doesn’t require PHP threads; 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 threads 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 threads

The number of PHP threads 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 threads for the next request.

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

Adding more PHP threads 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 threads, it can create a bottleneck, leading to performance issues.

With Kinsta, you can monitor PHP thread activity using the Analytics chart to see how often the PHP engine reached the maximum allocated PHP threads or by using Kinsta’s APM tool to identify performance issues and slow queries.

To view the PHP thread limit chart, go to Analytics > Performance, then scroll down to the PHP Thread Limit section.

PHP thread limit graph
PHP thread limit graph.

The chart shows how often your site has hit its maximum allocated PHP threads. For example, if your plan includes 4 PHP threads and all 4 are in use simultaneously, preventing the server from immediately handling new PHP requests, this would count as one instance of reaching the PHP thread limit.

However, this chart only tracks the number of times the limit was reached — it doesn’t show how long all PHP threads remained in use. To get a deeper insight into PHP performance, you can use Kinsta’s APM tool to identify slow queries and other PHP-related bottlenecks.

Enable the APM tool by navigating to your site’s APM tab and clicking the Enable APM button.

Kinsta APM tool in MyKinsta
Kinsta APM tool in MyKinsta.

How to add more PHP threads

To add more PHP threads to your site, you now have the option to use the PHP Performance Add-on in addition to upgrading your hosting plan. This add-on allows you to adjust the total PHP memory pool, the number of PHP threads, and the memory limit per thread based on your site’s needs.

You can enable the PHP Performance Add-on from the Add-ons page in MyKinsta, where you can increase the number of threads to handle more simultaneous requests or allocate more memory per thread for resource-intensive tasks.

Change your PHP pool size, thread count or memory limit
Change your PHP pool size, thread count or memory limit.

However, increasing threads without increasing the total memory pool will reduce the memory available per thread, which may affect performance for memory-heavy processes like large database queries or WooCommerce transactions.

If your site needs more PHP threads than your plan allows, upgrading to a higher-tier plan will also increase your thread count. For sites with unique performance needs, Kinsta also offers custom plans where you can configure the number of PHP threads and memory allocation as required.

For temporary traffic spikes, like sales events or high-traffic periods, the PHP Performance Add-on can be scaled up as needed and removed afterward, with charges prorated based on usage.

This feature is not yet available for all plans. You can check Kinsta Docs for more details on availability and how PHP threads and memory allocation work.

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 thread usage:

  1. Efficient caching — Implementing robust caching mechanisms can significantly reduce the load on PHP threads. By serving cached content to visitors, you minimize the number of requests that need to be processed by PHP threads, 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 threads 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 threads, their roles, and how to optimize their usage.

For personalized recommendations or to increase your PHP memory limit or PHP threads, please open a new ticket or email accountmanagement@kinsta.com.

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 300 technical articles majorly around JavaScript and it's frameworks.