Category: High Performance Optimization

Helpful WordPress wp-config.php Settings

wp-config

wp-config.php – one most important WordPress files, yet often overlooked. There are a number of great configuration gems you can add to your wp-config.php file to help with debugging, performance, and maintenance that I would recommend looking at if you use WordPress (there is surely something for everyone). All settings are documented: in the WordPress Codex but here are some of my favorite.

  • Specify the Number of Post Revisions
    define( 'WP_POST_REVISIONS', 3 );

    The default is set to 5 but a lower number can decrease database clutter.

  • Empty the Trash
    define( 'EMPTY_TRASH_DAYS', 15 ); // 15 days

    The default is set to 30 but if you are looking to make things tidier – you can easily lower the time between deleting items marked as trash.

  • Automatic Database Optimizing
    define( 'WP_ALLOW_REPAIR', true );

    The default is set not to optimize the database – so putting this in the wp-config will enable optimization.

  • Disable the Plugin and Theme Editor
    define( 'DISALLOW_FILE_EDIT', true );

    The default is set to allow editing. Users want the ability to edit theme and plugin files, but developers know better and know it is just a matter of time before save goes bad. Disallow it.

  • Save Queries for Analysis
    define( 'SAVEQUERIES', true );

    The default is not to save queries. As mentioned before in an earlier post this is a great way to debug and optimize WordPress.

  • Redirect Nonexistent Blogs
    define( 'NOBLOGREDIRECT', 'http://example.com' );

    If this is set when using WordPress Multisite – you can set up a redirect for the browser if the visitor tries to access a nonexistent blog so you can better control traffic.

Overall – there are a number of helpful settings available for you to explore by adding a line or two to to the wp-config.php file. It is well worth your time reviewing your site performance, needs, and data every so often to make sure your site’s performance is the best it can be. Take a few minutes to check out all the options available to you!

HOWTO: Keep Your WordPress Site Running Smoothly/Efficiently

At the end of the day, we all want the same thing: a fast, secure site that easily to maintain. While that is possible – we also need to spend some time on occasion reviewing the current theme, plugins, database, and your hosting environment.

Generally I recommend doing this with each major release of WordPress since you have to spend some time updating WordPress anyway.

Things to consider in order to make sure your site performs at it’s best:

WordPress

  • Is WordPress up to date?
  • Do you have automatic updates enabled for security updates?
  • Did you read about the changes in the most recent versions of WordPress so you know what changed/what to look for?
  • Are there any users that need to be deleted?

Plugins

  • Are your plugins up to date?
  • Do you have plugins that you no longer use? (if so DELETE them – don’t just de-activate them)
  • Are there plugins you can eliminate?
  • Are there other plugins out there that might work better/more efficiently?
  • Do any of your plugins rely on an outdated version of jQuery or other libraries?(hopefully not – but I have seen some break after WordPress updates)

Theme

  • Does your theme still function as expected after the update (custom views, etc)
  • Is there any new functionality you can add to it from the most recent update?
  • Are there functions/depreciated code you can eliminate?

Database

  • Do you have any custom tables that are no longer needed?
  • Do you have any old options in your options table that are no longer used?
  • Are your tables optimized?

Your Hosting Environment

  • Is your host still a good fit?
  • What sort of errors are in the web server error log?
  • Are you up to date with PHP/MySQL/security updates?
  • Are you sure…really sure you have backups running and can easily access them?

By going through questions like the ones above a few times a year – you will ensure your site runs smoothly and as efficiently as possible. It will also be considerably easier to troubleshoot when/if something goes wrong. Just remember – the end goal is to keep it simple and clean.

Analyze Your WordPress Queries

There are many ways to debug and optimize WordPress, and here is one more of my favorites: save queries for later analysis (from the Codex). If you are using a complex theme, several plugins, or even a few custom plugins – you may might notice your site is either slow, sluggish, or just seems to not load as fast as you would like.

Generally people will install a free theme or plugin(s) (I have seen sites with over 100 plugins) and think “wow – I have every possible custom functionality in place and I did not have to do any custom development!” Then the same proud individual will contact us because their site is not performing as they would like.

One of the first things we do is take a look at all the queries that are used on each page load and we do that by editing two files:

wp-config.php
define( ‘SAVEQUERIES’, true );

footer.php

<?php
if ( current_user_can( 'administrator' ) ) {
    global $wpdb;
    echo "<pre>";
    print_r( $wpdb->queries );
    echo "</pre>";
}
?>

Please note – these changes should only be used when debugging. If you keep them in place – it will have a definite impact on performance.

Once you have the changes in place (assuming you are logged in as the administrator) you will be able to view each query, what function called it, and how long the query took to execute.

From the output – you should easily be able to see what queries are most expensive, what plugins you might need to re-consider, etc.

Super Charge Your Site With CloudFlare

We have had a few clients recently come to us looking to help “speed up” their site. After tweaking server settings, themes, plugins, etc – we then also recommend something that has produced good results: CloudFlare.

From CloudFlare:

CloudFlare protects and accelerates any website online. Once your website is a part of the CloudFlare community, its web traffic is routed through our intelligent global network. We automatically optimize the delivery of your web pages so your visitors get the fastest page load times and best performance. We also block threats and limit abusive bots and crawlers from wasting your bandwidth and server resources. The result: CloudFlare-powered websites see a significant improvement in performance and a decrease in spam and other attacks.

Sound good? CloudFlare also claims:

On average, a website on CloudFlare
– loads twice as fast
– uses 60% less bandwidth
– has 65% fewer requests
– is way more secure
All for free!

They have different packages – from free to $20/month. If you have some time – take a look at their site, and give them a shot. We use them here and have been very happy with everything (they even have a WordPress plugin).

Site Optimization

I have been busy the past three months working on a site optimization project for a startup company where the code had been written by 10+ programmers who had come and gone over the last year. That left a big site with lots of unused and crazy CSS, images, javascript, and nasty HTML structure. I approached this project with two stages in mind:

  1. Start clean with CSS and XHTML. The first thing I did was unlink the main 5 thousand line CSS file along with a handful of others which was wreaking all kinds of havoc. I then went into every view, standardized the overall HTML structure (so it could hold it’s own without any CSS), and then only added in the CSS that was used.
  2. Maximize HTTP requests. The next phase will involve spriting images and pairing down and combining javascript so the number of HTTP requests goes way down.

The initial results:
Total HTTP Requests: 192
Total Size: 1353141 bytes

After the first stage (finished today), the general results:
Total HTTP Requests: 67
Total Size: 693064 bytes

After stage two is completed – I think I can get those numbers down by another half.

From Yahoo!:
“80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.”

Why does all this matter? Think of a big, busy site. Think about the number of users – and then multiply that by the number of requests as well as the size of each page load. If you want good performance from your site – the pay off from optimizing your site will really pay off. It is pretty easy to go through your site and cleanup small things that over time will really add up. Not using a javascript you once did? Remove it from the header. Redid the site but still have a link to the old CSS “just in case”? Get rid of it! Remember, a little goes a long way.