In this article, will be talking about the main points recommended to optimize your WordPress for speed and scale with Pagely's system.
The items are not in any specific order, but we have seen if they are generally applied, it makes a huge difference in how fast a site is and how many CPU/memory resources are conserved (ie. scale better).
This overview goes into using terminal to debug and confirm some things like cache, but some commands could be substituted by looking at the requested page header responses via the browser.
This article covers the following topics:
Page Caching Layer (Most Important)
This layer primarily involves hitting the page caching layer of our stack. This is enabled and installed by default on every Pagely VPS.
Checking for Cache Hits
To confirm that page caching is working properly, look for the X-Cache-Status: HIT
header in the page response.
Via command line this would be:
curl -I -X GET http://www.example.com/ | grep -i "HTTP/\|Cache\|Cookie"
After running that command twice, it should give a response that looks like the following:
HTTP/1.1 200 OK
X-Cache-Config: 0 0
X-Cache-Status: HIT
Handling Cache Misses
If it shows X-Cache-Status: MISS
or X-Cache-Status: BYPASS
, something is causing it to be skipped. This is usually due to a PHPSESSID cookie being set, similar to the following:
Set-Cookie: PHPSESSID=dcdb03bb64771ce5c24557f51f784e24; path=/
Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/
Try to avoid setting a session cookie when the pages don't have to be dynamic. A helpful command to find what theme or plugin is causing it is:
cd ~/sites/www.example.com/
find ./wp-content/ -type f -name '*.php' -exec grep -H "session_start(" {} \;
Avoid Ajax POST/GET Requests to admin-ajax.php
Upon requesting the homepage or certain pages on the site, there are sometimes plugins or themes which make an XHR request to admin-ajax.php.
Under high traffic load, these requests have a tendency to overload the server resources due POST requests not being cacheable. This means that a dynamic PHP worker will have to serve every single one of these requests and use up a lot of the server's CPU.
The first thing to do is to find that they are happening, then to locate which plugin or theme is causing them to occur.
Our recommended plan of action is to then remove or disable them, as it's more important for the site to remain up, rather than overloading the resources so no other visitors are able to visit the site.
Redis Object Cache
Transients API, Say No to MySQL
This offloads queries being made into the Redis object store, so it speeds up and helps overall site performance.
At Pagely, we offer Object Cache Pro to all of our VPS customers, which can dramatically improve your WordPress site's performance.
HTTP/2 - Become One with It.
HTTP/2 is an update to the protocol by the Internet Engineering Task Force (IETF). You'll get a nice performance boost with compatible clients, and anything that doesn't support it will gracefully fallback to the old protocol.
The performance gain is achieved by only requiring one persistent connection to the server in order to load the website's assets. Other benefits are prioritization of higher resources, header compression, and multiplexing (multiple requests over the same connection).
In order to support HTTP/2, an SSL certificate will need to be installed on your application. Once that's done you may contact support for further instructions.
Nginx-Only Mode
Switching your site to Nginx-only mode can help alleviate load caused by too many dynamic PHP requests with a built-in pressure-release valve. What does that mean? Head on over to our guide for NGINX+Apache and NGINX-only modes for more in-depth information!
Helpful Tools/Commands
- Pingdom: You can see how long the entire site takes to load; helpful to see which assets (js/images/css) take a while to load.
- Query Monitor: This plugin is useful for finding slow queries on the front and back end. We recommend enabling the plugin as needed.
- NewRelic: We can connect New Relic so you can get some detailed reporting about your application performance.
- To view CPU and RAM live, you can use
htop
(via SSH) - Use curl to check the headers of the site:
curl -I -X GET http://www.example.com/
In the header response,
X-Cache-Status: HIT
could be used to verify if that page cache is hit.