Performance Edit

This section will cover the basics on configuring services for performance with WordPress.

CachingCache A cache is a component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. Caching

WordPress has a lot of dynamic functionality, but this comes at a cost. Tasks such as processing PHPPHP PHP (PHP: Hypertext Preprocessor) is a general-purpose scripting language especially suited to web development. PHP code is usually processed on a web server by a PHP interpreter. On a web server, the result of the interpreted and executed PHP code would form the whole or part of an HTTP response., querying the databaseDatabase A database is an organized collection of data. Access to this data is usually provided by a "database management system" (DBMS) consisting of an integrated set of computer software that allows users to interact with one or more databases and provides access to all of the data contained in the database. Because of the close relationship between them, the term "database" is often used casually to refer to both a database and the DBMS used to manipulate it. and collecting information from external APIs all take resources and time.

Caching saves time for potentially heavy tasks by reusing previously computed results, rather than calculating them for every page view.

CachesCache A cache is a component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. typically expire after a certain amount of time and are regenerated so the most recent content is displayed. When items are served from cacheCache A cache is a component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. they have a faster response time, often coming from memory, and take load off the serverServer A server is a piece of computer hardware or software that provides functionality for other programs or devices. Typical servers are database servers, file servers, mail servers, print servers, web servers, game servers, and application servers..

In a typical page load, various caches might be checked in the following order:

  1. Local Browser cache / Local Storage / Web App Manifest
  2. Content Delivery Network (CDN)
  3. Full Page Cache (Reverse Proxy; RAMRAM Random-access memory (RAM) is a form of computer memory that can be read and changed in any order, typically used to store working data and machine code. or SSD with NginxNGINX nginx is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. Nginx is free and open-source software, released under the terms of the 2-clause BSD license.+)
  4. Full Page Cache (Static; PHP)
  5. Opcode Cache
  6. Object Cache (wp_options, transientTransient WordPress Transients offers a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted. APIAPI An Application Programming Interface (API) is a computing interface that defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc.)
  7. Fragment Cache (Database, static files, transient API)
  8. TransientsTransient WordPress Transients offers a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted. API (ObjectObject In computer science, an object can be a variable, a data structure, a function, or a method, and as such, is a value in memory referenced by an identifier. Cache or Database Cache)
  9. Database Cache
  10. File Storage Cache (Static Files, SSD or spinning disk)

Each caching instance may be a different domainDomain A domain name is an identification string that defines a realm of administrative autonomy, authority or control within the Internet. Something like, server, or compute instanceCompute instance In Cloud Computing, an instance is a virtual server., either routed by the local machine, the remote server cluster, or any intermediary computer along the request chain.

Each cache may have any configuration of:
Data storage: RAM, SSD, or spinning hard drives. Physical connection, or data over network.
Input/Output latency: Connection from local or remote server motherboard to RAM, Data I/O, or network I/O.

For any given page load, speed and user experience will result from the combined latency of all services, and the order they are processed as users interact with a web application.

(Example: CSSCSS CSS is an acronym for cascading style sheets. This is what controls the design or look and feel of a site.; Generated by JavaScriptJavaScript JavaScript, often abbreviated as JS, is a programming language. It has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions. Alongside HTML and CSS, JavaScript is one of the core technologies of the World Wide Web., PHP or pre-processor. Sent over network. Earliest display: Inline script within first HTTPHTTP The Hypertext Transfer Protocol (HTTP) is protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser. packet of first HTMLHTML Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. HTML describes the structure of a web page semantically and originally included cues for the appearance of the document. response. Typical: Loaded by many plugins in many files over many requests. Middle-ground: combined file, cached locally, to CDNCDN A Content Delivery Network (CDN) is a geographically distributed network of proxy servers and their data centers. The goal is to provide high availability and performance by distributing the service spatially relative to end users. CDNs have grown to serve a large portion of the Internet content today, including web objects (text, graphics and scripts), downloadable objects (media files, software, documents), applications (e-commerce, portals), live streaming media, on-demand streaming media, and social media sites., or server RAM or SSD.)

Content Distribution Network (CDN) Cache Content Distribution Network (CDN) Cache

Content distribution networks are designed to optimize the network latency between servers and visitors from different geographical locations. Data is distributed amongst endpoints and then visitors get served from the endpoint which is closest to them.

In addition to optimizing networking latency, CDNs can act as another layer of static and/or full-page caching running on all those endpoints.

It’s important to make sure that CDNs are working well with all your other caching systems and that it purges caches on all endpoints when you request that from your main server. Otherwise, people in certain areas may get old results which is generally an issue that’s difficult to troubleshoot.

Top ↑

Full Page Cache Full Page Cache

In order to display your content, WordPress does a lot of work under the hood, and all those calculations require server resources and time to complete. For starters, the PHP service on the server has to process the request, load WordPress coreCore Core is the set of software required to run WordPress. The Core Team builds WordPress., your themeTheme A theme dictates the style and function of your WordPress website. Child Themes derive from the main parent theme. PHP files and all PHP scripts coming from your plugins. The majority of those PHP files make requests to your database, too, which adds to the overall resource footprint of your site.

The best way to cache these requests is to use a reverse proxy like NGINX or Varnish which stores the output directly into the server memory. That saves a lot of processing power because cached content is served straight out of the reverse proxy without hitting your web serverServer A server is a piece of computer hardware or software that provides functionality for other programs or devices. Typical servers are database servers, file servers, mail servers, print servers, web servers, game servers, and application servers., the PHP service, or your database service at all. If a reverse proxy is not available on your current server setup, you can fallback to storing cached content into your file system. It’s slower than reverse proxies and a hit reaches your web server and your PHP service at least once, so it can direct the request to the proper cached file but still – it’s much faster than doing all the computing for every request.

Full Page Caching stores the HTML output of a request, but all the CSS, JS, images and font files will have to be loaded separately too. They are handled separately and optimizing them is worth investing the time and effort. Static caching can have great effect on those resources. You can often use the same reverse proxy to static resources in the server memory – CSS, JS, Fonts, Images and serve them directly.

It’s important to have the ability to expire caches when necessary to avoid serving visitors old data. When available, selective caching is preferred over purging the entire cache, to avoid the cost of WordPress regenerating every page for the site. Furthermore, it’s good practice to exclude certain types of pages from your full page caching completely because they are different for each user. For example, if you have an online store, it’s imperative that your cart, checkout and profile pages are completely dynamic. In general, it’s a good idea to exclude all logged in users from the cache because they are supposed to see personalized content. Another important aspect is the default caching period, which can be different for each website depending on how often data is changed.

Top ↑

Object Cache Object Cache

In 2005, WordPress introduced its internal object cache — a way of automatically storing any data from the database (not just objects) in PHP memory to prevent unnecessary queries. However, out of the box, WordPress will discard all of those objects at the end of the request, requiring them to be rebuilt from scratch for the next page load.


What does this mean? Think of a standard WordPress homepage displaying the most recent posts. Each of these posts has quite a bit of information associated with it WordPress must look up such as the author, categories, tags, and excerptExcerpt An excerpt is the description of the blog post or page that will by default show on the blog archive page, in search results (SERPs), and on social media. With an SEO plugin, the excerpt may also be in that plugin’s metabox..

Support for a persistent object cache gives WordPress, plugins, and themes, a place to store that data for reuse. While these items are cached, PHP execution time is improved while lessening the load on the database. It’s particularly helpful in situations where much of the page is difficult to cache from the front-end, like for authenticated traffic or e-commerce applications.

For these reasons, persistent object caching support is commonly offered with managed WordPress hostingHosting A web hosting service is a type of Internet hosting service that allows individuals and organizations to make their website accessible via the World Wide Web..

Transients are inherently sped up by caching plugins, where normal Options are not. A memcachedMemcached Memcached is a general-purpose distributed memory-caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source must be read. Memcached is free and open-source software. pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the Plugin Directory or can be cost-based plugin from a third-party., for example, would make WordPress store transient values in fast memory instead of in the database. For this reason, transients should be used to store any data that is expected to expire, or which can expire at any time. Transients should also never be assumed to be in the database, since they may not be stored there at all.

source: WordPress Codex

Top ↑

Opcode Cache Opcode Cache

The web server must read, compile, and run each PHP script. An opcode cache stores a compiled copy of each PHP script in memory or on disk. When the web server starts processing PHP scripts for WordPress, the web server checks the opcode cache for a cached copy of the PHP script. If there is a cached copy, the web server can skip straight to running the PHP script using the cached copy instead of having to read and compile the script again. Skipping this reading and compiling PHP scripts can greatly improve the web server’s resource usage and enable WordPress to serve many more requests than it might have been able to otherwise. It’s particularly helpful for dynamic content and authenticated traffic, where full page caching isn’t as effective.

As with any cache, opcode caches can keep changes from taking effect until the cache expires or is purged. With opcode cache specifically, this means older versions of the compiled PHP code will be loaded. When updating plugins, themes, or WordPress core, the appropriate files should be purged from the cache to avoid continuing to load the older versions.

Top ↑

Fragment Cache Fragment Cache

This caching method allows saving sections of otherwise non-cacheable dynamic website content. It can help especially for sites where the majority of the page is static, but has certain dynamic elements, like a shopping cart, or for membership sites.

In the WordPress context, developers often store parts of the page using the WordPress transients/object cache API. In these cases, providing a persistent object cache will allow that caching to happen outside of the database.

Storing these fragments separately in a front end cache is not natively supported by WordPress, and means both manually configuring the sections of the page to be cached, and configuring your front-end cache, whether it be Nginx, Varnish, or otherwise, to support fragment caching. This is usually an advanced technique, and reserved for sites or hosting platforms with very high dynamic traffic needs.

Top ↑

Purging / Busting / Clearing Caches Purging / Busting / Clearing Caches

Purging caches is as important as storing them. You have to make sure that all layers of caching are cleared when necessary.

Fragment caching is the temporary storage of expensive or long-running server-side operations to avoid taxing web servers and delayed delivery to visitors. It’s become a common practice for operations such as generating Menu markup, WidgetWidget A WordPress Widget is a small block that performs a specific function. You can add these widgets in sidebars also known as widget-ready areas on your web page. WordPress widgets were originally created to provide a simple and easy-to-use way of giving design and structure control of the WordPress theme to the user. markup and slow MySQLMySQL MySQL is an open-source relational database management system (RDBMS). MySQL is free and open-source software under the terms of the GNU General Public License. or HTTP responses. Core currently uses transients to cache HTTP calls to The community site where WordPress code is created and shared by the users. This is where you can download the source code for WordPress core, plugins and themes as well as the central location for community conversations and organization. APIs for updates and events.

Fragment caching is particularly beneficial when appropriately paired with full-page caching. Perhaps there’s uniform <footer> markup displayed on every page that can be temporarily stored. When the server needs to rebuild static cache files and a fragment is found, it saves the server from running Menu/Widget queries to generate the footer markup on every page.

Significant caution should be exercised blanket caching Core resources. If a site Menu relies on dynamic .current-menu-item classes, storing the menu markup in a fragment will “burn” that class in, no longer highlighting the correct page as a user navigates. Any caching of WordPress Core resources should be opt-in and integrate an appropriate flushing mechanism for when users modify the resource.

The Transients API should always be used for fragment caching instead of directly using wp_cache_* functions. In environments without a persistent Object Cache, set_transient() will store cache values in the database in the wp_options table. However, when Object Cache is enabled, set_transient() will wrap wp_cache_set().

Top ↑


PHP (PHP: Hypertext Preprocessor) is a popular programming language on the Internet. PHP turns dynamic content, like that in WordPress, into HTML, CSS, and JavaScript that web browsers can read. WordPress is written primarily in PHP, and a server must have PHP in order for WordPress to be able to run.

As PHP is an interpreted language, its version and configuration has a large impact on how well and whether WordPress will run.

Top ↑

Version Version

When possible, PHP 7.4 or greater should be used to run WordPress. As of the writing of this document, PHP 7 is the only major version of PHP still receiving active development and support. The PHP group regularly retires support for older versions of PHP, and older versions are not guaranteed to be updated for security concerns.

At the same time, newer versions of PHP contain both security and performance improvements, while being accompanied by new features and bug fixes, which are not guaranteed to be backwards compatible. However, extreme care must be taken when upgrading the version of PHP. While WordPress is compatible with the latest releases of PHP, sites built to use older versions of PHP may not be compatible due to their included plugins and themes.

If upgrading to PHP 7.4 is not immediately possible, upgrading to PHP 7.2 should be done as soon as possible. PHP 7.2 is the oldest version of PHP that is still receiving security patches. While WordPress may work with older versions of PHP, these versions have reached official End Of Life, and running outdated PHP installations may expose your site to security vulnerabilities.

More information about the support versions of PHP can always be found on PHP’s supported versions page.

When upgrading PHP, it’s a good practice to test sites for compatibility before upgrading. If you offer multiple environments, such as a staging and a production environment, PHP version should be configurable separately for each environments. This will allow users to test newer version of PHP in their non-production environment and resolve any issues before upgrading PHP version in the production environment.

There’s a useful WP-CLI command for performing a general compatibility check, but be aware that it is not 100% accurate.

Top ↑

Configuration Configuration

PHP is primarily configured using a configuration file, php.ini, from which PHP reads all of its settings and configuration at runtime. This usually happens through CGI/FastCGI, or a process manager like PHP-FPM.

You can see detailed information about each of these directives in the official PHP documentation.

Timeouts Timeouts

There are several timeout settings on a system that limit different aspects of a request. When configuring your timeouts, it’s important to select values that work well together. For example, it doesn’t make sense to have a very high script execution timeout on your PHP service, if the ApacheApache Apache is the most widely used web server software. Developed and maintained by Apache Software Foundation. Apache is an Open Source software available for free. timeout is lower than that – in such case, if the request takes longer, it will be killed by the web server no matter your PHP timeout setting is.

Note that processes take different amount of time, depending on the server load, and those limitations are placed to ensure that your server functions properly. If you have high server load, processes may take longer to complete thus causing a cascade effect leading to even more server load. That’s why it’s a matter of balance between giving enough time for your scripts to be compiled and ensuring that you’re within normal server loads.

The primary PHP timeout can be set with the max_execution_time php.ini directive. This limits code execution, and not system library calls or MySQL queries, except on Windows, where it does.

The maximum time allowed for data transfer from the web server to PHP is specified with the max_input_time php.ini directive. It is usually used to limit the amount of time allowed to upload files. It’s important to note that the amount of time is separate from max_execution_time, and defines the amount of time between when the web server calls PHP and execution starts.

Top ↑

Memory Limits Memory Limits

The maximum amount of memory that PHP is allowed to use per page render is specified with the memory limit php.ini directive.

In addition to setting memory limits within PHP, WordPress has two memory configuration constants that can be changed in the wp-config.phpwp-config.php One of the most important files in a WordPress installation is the wp-config.php file. This file is located in the root of your WordPress file directory and contains your website’s base configuration details, such as database connection information. file. WordPress will raise the PHP memory_limit to these values if it has permission to do so, but if the php.ini specifies higher amounts, WordPress will not lower the amount allowed.

define('WP_MEMORY_LIMIT', '128M');

This option declares the amount of memory WordPress should request for rendering the front end of the website.

define( 'WP_MAX_MEMORY_LIMIT', '256M' );

Since the WordPress backend usually requires more memory, there’s a separate setting for the amount, that can be set for logged in users. This is mainly required for image uploads. You can have it set higher than the front end limit to ensure your backend has all the resources it needs.

Top ↑

File Upload Sizes File Upload Sizes

When uploading media files and other content to WordPress using the WordPress admin dashboard, WordPress uses PHP to process the uploads. PHP’s configuration includes limits on the size of files that can be uploaded through PHP and on the size of requests that can be sent to the web server for processing. These will need to align with the server’s timeouts, discussed above.

The limit on the size of individual file uploads can be configured using the upload_max_filesize php.ini directive.

The limit on the entire size of a request that can be sent from the web server to PHP for processing can be configured using the post_max_size php.ini directive. The value for post_max_size must be greater than or equal to the value for upload_max_filesize. PHP will not process requests larger in size than the value for post_max_size.

Note that post_max_size applies to every PHP request and not only uploads, so it may become important to address separately if a site processes a large amount of other data included with the request.

Top ↑

Replacing WordPress’ CronCron Is a time-based job scheduler in Unix. Users that set up and maintain software environments use cron to schedule jobs to run periodically at fixed times, dates, or intervals. Triggers Replacing WordPress’ Cron Triggers

The wp-cron.php script is responsible for causing certain tasks to be scheduled and executed automatically. Every time someone visits your website, wp-cron.php checks whether it is time to execute a job or not. Even though these checks are small and fast they consume time and produce load. For this reason, it’s worth considering setting the DISABLE_WP_CRON constant and using an alternative method to trigger WordPress’ cron system.

Note: If you’re interested in improving this handbook, check the Github Handbook repo, or leave a message in the #hosting-community channel of the official WordPress Slack.

Top ↑

Changelog Changelog

  • 2021-05-27: Fixing infoboxes
  • 2021-02-17: Changelog added.
  • 2020-11-09: Lifted PHP Recommendation to 7.4.
  • 2020-06-02: Published from Github.

Last updated: