High Performance WordPress and Server – Part II – Theme Development

High Performance Wordpress and Server - Part II - Theme Development

Posted:  July 1, 2016

High Performance Wordpress and Server - Part II - Theme Development

In part I, I walked you through my server setup to achieve a 1 second load time for my site.  It is a WordPress site, with a custom theme I developed.

I gandered at the possibility of by-passing WordPress’s front-end engine, however, I found myself needing some of the built-in functionality WordPress offers.  Items like custom posts, pages, and even posts are simple sql queries, however; widgets, shortcodes, and most plugins then become unavailable.

So, I delved into the realm of research and found WordPress core functionality offered the functionality I required, with very little performance hit; so I decided to simply extend some memcached functionality when pulling my pages/posts/widget/etc…

The only thing I found that I lost was time, and in the end drastically improved the load time of my site, as well as drastically improved the number of concurrent connections to it.

I managed to keep this 1 second load time with 250 concurrent users per minute.  Of course, load time increased as the numbers grew, and in the end I found that my server/site setup was able to effectively handle 1238 concurrent connections per minute before I hit the 7 second load time mark.    At this point I called it a viable project, implemented my code… here we are 🙂

Now I won’t get into the details of theme design and development here, however, have a look over at the codices for the how-to’s you will need to read through to go further here.

Once you get the basics down pat and your site is running how you like, add a little more code to force your templates to utilize memcached and cache your theme pages in server memory for lightning fast transfer and rendering.

At the top of each of my theme files, I have put the following code:

// Fire up an instance of Memcached
$mc = new Memcached();
// If it's not already done, set the server
	$mc->addServer('', 11211);
// Start our output buffer
// Load up our sidebar
// Grab the content from it
$sidebar = ob_get_contents();
// End our buffer so we can process the rest of the page


As you can see above, this is far from complete.  You will want to add in anything that pre-fires/pre-loads after the start of our output buffer.  This way we can catch it, and cache it before it renders

The rest is basically up to you, as the rest of the code is pretty basic… check for the cached object, if it’s there, present it, if not present the page and cache the object.

For instance:

$ret = '';
$m = $mc->get('YOURKEY');
if($m) {
	echo $m;
} else {
	$ret = 'Your stuff here...';
	$mc->set('YOURKEY', $ret);
	echo $ret;


You will want to name your KEY accordingly, for instance, for my posts, the key name is set to “post_the-post-title”.   This way Memcached knows what to present, and there will be no collisions.

Of course, if you do not follow the basics of web design, this may be a moot point.  Make sure you are concatenating and minifying where you can, optimizing all your images where you can to get the best optimal results, and setting the proper browser caching/gzipping on all static resources.

Now, as much as I hate to admit it, there are a couple of plugins I am going to go out on a limb and recommend to you all.  All are caching related, and all are the ones I have used extensively with great success.


Some of the configuration options will depend on your setup, however, if you followed along with Part 1, and set your server up like that, you should be good 😉

  • Nginx Cache
    • Plugin Homepage: https://wordpress.org/plugins/nginx-cache/
    • Settings:  Change the cache path to your location, and make sure the “Automatic flush” is checked off
  • WP Super Cache
    • Plugin Homepage: https://wordpress.org/plugins/wp-super-cache/
    • Settings:
      • Easy Tab: Turn on Caching
      • Rest of settings defaults are fine, though I did up the timeout to 3600 for everything
    • Plugin Homepage: https://wordpress.org/plugins/wp-ffpc/
    • Settings:
      • Cache Type Tab:
        • Select backend: PHP Memcached
        • Timeouts: 3600
      • Backend Settings Tab:
        • Hosts: add your memcached server ip adress and port; ie…
          • accepts a comma-delimited list of servers…
  • Notable Mentions 🙂
    • WP Smush – helps reduce image file sizes
    • WP Clean Up – keeps your database clean and optimized
    • Lazy Load – hooks into your images and only loads them into the page when they enter the viewport
    • WP Performance Score Booster – removes the versioning querystring on static resources

Kevin Pirnie

20+ Years of PC and server maintenance & over 15+ years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.