High-Performance WordPress Basics

Getting started with high-performance WordPress requires understanding the concepts of speed, scale, and elasticity.

What do we mean by WordPress performance anyway?

You cannot separate the definition of “performance” from the overall purpose of the site itself.

If you’re a small business who just needs to post your store’s hours and contact info, a 1-second improvement in load-time may not be all that important to you — especially once you consider the additional cost. Everyone wants a faster more efficient site, but time is not an infinite resource and–unless you are Bill Gates or Warren Buffet–neither is money.

But if you are a search marketer, obsessing over page rank, bounce rates and conversions then 1 second can change your world and will probably be worth every penny you put into it.

As you read this book always keep recommendations in context of your overall purpose.

Dimensions of WordPress Performance

There are three primary consideration when talking about WordPress Performance:  speed, scale and elasticity. This ebook examines all three but will be mostly concerned with speed and scale. Elasticity comes mostly from the server/infrastructure and as such will only be dealt with in the hosting discussion.

Speed is an easily understood concept. How fast does my page load damnit! That’s all you need to know. It’s not quite this simple of course, but for the introductory chapter it’ll suffice.

Scale is a slightly more complicated concept. What do we mean when we ask can my application scale?

Computing power is a limited resource and the performance of your website or application will be impacted by the available and consumption of that resource.

An analogy.

Imagine a bagel shop owner in a small town. They get healthy foot traffic but not enough to afford an employee so they do everything themselves. They take the orders, make the bagels, ring the register. This can totally work so long as the number of people coming in and placing orders isn’t any more than can be served relatively quickly. But as more people come in, orders pile up, wait times increase, and the customer experience is wrecked.

What worked at the scale of one customer every five minutes broke down once there were two.

Of course our intrepid Bagel-ista will inevitably have to hire someone to help her out. But if she waits too long she’ll risk losing business because of the poor customer experience. She might just go ahead and hire early expecting the increasing demand. But what if business grows slower than expected? She’s spending more than she can afford on help she doesn’t need yet.

WordPress Scaling is a Balancing Act

The same goes for websites and application. You could spend thousands of dollars a month on sophisticated Amazon AWS machinations but not have a single customer to support the investment. Likewise you could go super-cheap with BlueHost or DreamHost and end up with a crashed server on the biggest day of your business.

It’s a balancing act. And there is no right equation or server or plugin that can make the decision for you. But you can plan ahead, accepting that those growing pains will happen and putting yourself in a position to scale as rapidly as possible when that time comes.

Strategies For WordPress Performance and Scale

Given the analogy above you can see to competing strategies developing, an aggressive or over-investment strategy and a conservative or under-investment strategies. Both have advantages and disadvantages and either can be used successfully.

Aggressive v. Conservative

The key consideration of the aggressive strategy is a complete intolerance downtime. In the movie “Social Network”, Mark Zuckerburg is memorably quoted saying:

Okay, let me tell you the difference between Facebook and everyone else, we don’t crash EVER! If those servers are down for even a day, our entire reputation is irreversibly destroyed! Users are fickle, Friendster has proved that.

This is a supremely aggressive strategy, but it was probably warranted given that the ONLY market advantage Facebook had was popularity.

I think too often though those with sites/applications very different from Facebook feel they need the same strategy.

Downtime is definitely a problem, especially when it happens at an inopportune time.The advantage to an aggressive strategy is that if done right, a promo video going viral will be no big deal. But you could easily spend thousands per month on a servers you don’t need in the meantime.

A Conservative approach can be just as effective. In most web hosting scenarios, you can upgrade your site to better hardware and be back online in no time. A few minutes, or even a couple hours downtime, while inconvenient can be tolerated if expected and planned for.

We will discuss this more in later chapters but this concept of expanding quickly to accommodate a change in traffic is known as “elasticity”.

In the next chapter we will ask the question “How do I pick a WordPress Host?”

Registration Forms: What’s New in 1.5

Last week I released version 1.5 of my Simplr Registration Forms plugin. The new version includes some big fixes and requested features. Particularly, this version now supports WP Multisite and has a few addition profile fields that can be added to the default form. It also includes better security, via WP nonces, and better field validation.

But the most important change is that it includes hooks and filters that allow it to be extended by you, the user.

For instance, let’s add a field to our form that requests the user’s zip code. First, in your functions.php file create a function for displaying the field:

function sample_zip_field($form) {
 $form .=  '<div>';
 $form .=  '<label for="zip">Zip Code:</label>';
 $form .=  '<input type="text" name="zip" value="'.$_POST['zip'] .'"/><br/>';
 $form .=  '</div>';
 return $form;
}

Note that this function receives the parameter $form and then returns $form. Failing to return the form will make the entire registration form disappear. To add this form to the registration use:

add_filter('simplr_add_form_fields', 'sample_zip_field');

But then we also need to make sure this data gets saved when the for gets saved. So you’ll need to create a function for that as well.

function sample_save_meta($user_id) {
if(isset($_POST['zip'])) {
 add_user_meta($user_id, 'user_zip', $_POST['zip']);
 }
return $user_id;
}

Note that in order for this function to work properly it has to receive the $user_id. It is also good practice to return the $user_id at the end of the function, though not necessary.

To make sure your save function is called use the hook:

add_action('simplr_profile_save_meta','sample_save_meta');

With these two “hooks”, you can customize the registration form however you want. You could even set up your field function to only display on certain pages, making it form-specific.

Finally, I’ve also added filters to the labels on the default form fields so you can change them at will. For instance, to change username to “screen name” use the following.

function sample_label_username($label) {
 $label = "Screen name: ";
 return $label;
}
add_filter('simplr_label_username','sample_label_username');

I hope you find the changes useful.

WordPress 2.8 Release – Widgets Upgraded Big Time

WordPress 2.8 is finally out. There are some key improvements for the casual WordPress user including easier theme addition. Like plugins, you can now browse the WordPress.org theme gallery from within your WordPress admin screen. One click and your theme is installed.

For the wordHeavy user, that is the designer/developer building their content management system on the wordpress platform, there isn’t all that much to be excited about. The easy theme feature is likely to further centralize theme development within the grips of WordPress.org theming rules. Not that there’s anything inherently wrong with this, I just worry about those designers who charge for their creations loosing market share to “free” themes.

Perhaps WordPress will come up with a more inclusive gallery system? Or maybe an enterprising developer will develop a competing gallery that can be installed with a simple plugin.

The one development I’m looking forward to using is the widgets. As a freelancer, you have clients who need a specific sidebar widget. A special campaign logo for instance. The need is small enough that it isn’t worth the time developing a custom plugin for the widget (even though it really doesn’t take that long). Instead, I routinely use simple text widgets to paste in the small bits of code.

Trouble is you can’t save a text widget for later use. So the client one day feels a little adventurous, start playing with widgets … they are fun to play with … and accidentally delete your modified text widget. Doh! Not that big of a deal, but a real pain in the ass.

But starting with 2.8, widgets can be made “inactive,” which means they are saved in the system. Sweet!!! Now all those little widgets can be safe from unnecessary annihilation at the hands of the unsophisticated end user.

Actually, they are not entirely safe. For some reason the WordPress developers didn’t take the next logical step. When you have a widget in the sidebar and click the “remove” action, the widget doesn’t dump into the inactive bin, it is DELETED! I think it would make sense for the to go to the inactive bin first and to have widgets only deleted from the inactive bin. That’s what I get for not keeping up with the WordPress developers email list. Oh well, maybe 2.9 right?

The other improvement on widget management is that you no longer have to click which sidebar you want to show. Nor do you have to save the widget (clicking the “done” button) and then also save the sidebar (clicking “save changes”). Now all the options and functionality are on one page. That reduces the number of needed clicks to add a widget by half. Little stuff for most, but big stuff for heavy WordPress users.