Code,CoolStuff,Fun,PHP,WordPress
4 July 2010 8 Comments
Some times I like to look at metrics. Because I am bored? Probably. Without metrics how can really compare things. In any case I wanted to see the difference in the number of queries, generation time and peak memory usage between WordPress 2.9.2 and WordPress 3.0.
One of the things that I have heard people say since the release of WordPress 3.0 is that it is noticably faster. “Is it really?”, I asked myself. No, not out loud…or was it? Generally as much as we would like to make things faster from one release to the next, it doesn’t really happen that way. There are new features added, rewrites of code, a new default theme and in the end metrics change.
So what really changed in the way of these 3 aspects of number of queries, generation time and peak memory usage?
2.9.2:
- 18 queries
- 0.173 seconds
- 15.901 MB peak memory used
3.0:
Kubrick
- 16 queries
- 0.209 seconds
- 18.301 MB peak memory used
Twenty Ten
- 15 queries
- 0.212 seconds
- 18.32 MB peak memory used
I have provided results as well for Twenty Ten, but so that we can perform a more apples to apples comparison we will use Kubrick. We have reduced the number of queries by 2 from 2.9.2 to 3.0, but it took 0.036 seconds longer to generate the page. In addition we now consume 2.4 MB more memory to generate the output.
I used the following code, placed at the very end of footer.php of the default theme for 2.9.2 and the very bottom of footer.php in twentyten. In 2.9.2 I removed the timer_stop line that already existed in the footer.php of the default theme.
<!--
<?php echo get_num_queries(); ?> queries
<?php timer_stop(1); ?> seconds
<?php echo round(memory_get_peak_usage() / 1024 / 1024, 3); ?> MB Peak Memory Used
-->
The testing set up:
- Ubuntu 10.04
- Apache 2.2.14
- PHP 5.3.2 (Only enabled modules were mysql, gd and curl)
- MySQL 5.1.41 (With all caching disabled)
- Fresh installs of WordPress without any enabled plugins or modifications
- Tests performed using curl against the front page
- Averages over 25 tests per install
Anyway, not really the most comprehensive metrics gathering test, but just something to look at. But in the end, is WordPress 3.0 any faster? With an absolute default install, no. Does it matter that 3.0 is ever so slightly slower? No. Should I be running WordPress 3.0 now? Yes!
Hopefully you find this post useful and that I didn’t waste 15 minutes of my day that I will never get back to talk about something you could care less about.
CoolStuff,HowTo,WordPress
30 June 2010 3 Comments
Recently I have been getting a lot of questions about how to use a MySQL socket in place of the DB_HOST constant for WordPress in the WordPress IRC channel.
Fortunately this is pretty easy, unfortunately if you are using the web based installer you cannot specify a socket in the “Database Host” field. However, you can do things the manual way and copy wp-config-sample.php to wp-config.php and go that route.
The first thing you need to do is determine the path to the MySQL socket. By inspecting my.cnf you would need to look for something that looks like:
socket = /var/run/mysqld/mysqld.sock
If you don’t have access to look at my.cnf you can try to run the following MySQL query:
SHOW VARIABLES LIKE 'socket';
Now crack open your wp-config.php file and set DB_HOST to ‘:/path/to/mysql.sock’. Take careful note of the ‘:’ (colon) preceding the path. In my example the define for the DB_HOST looks like:
define('DB_HOST', ':/var/run/mysqld/mysqld.sock');
CoolStuff,Fun,HowTo,PHP,Plugins,Questions,Uncategorized,WordPress
25 April 2010 5 Comments
Normally I start these posts with “Every so often someone asks a question in the WordPress IRC channel that sparks my interest”, however today, to my great surprise someone actually caught my attention on the wp-hackers mailing list.
For those of you who didn’t click through, the question was:
Couldn’t find this on forums or anywhere else.
What can I test to check if wp_footer was placed on the theme?
Before any replies came in I was already interested and when Peter Westwood replied with “The other way to do it is to do a http request based test which a special query arg on which you output a string on wp_footer.”, I was on the hook.
I spent a few minutes writing up a test plugin, to perform only this functionality and responded back to the list. It was pretty well accepted and I got a few comments from Ozh and Andrew Nacin on Twitter. One of the comments was actually an idea, to extend the checks to make sure that the calls to <?php wp_head(); ?> and <?php wp_footer(); ?> were in the proper places in the code.
Before I get to the code, I want to spend a little time talking about the significance of wp_head() and wp_footer(). These 2 functions are the key to functionality of a lot of plugins and are the real work horses of themes. The wp_head and wp_footer functions allow WordPress core and plugins to hook into your theme either directly before the </head> or </body> html tags in your theme and perform actions. The majority of the time these actions are used to output style sheets or JavaScript, for use by plugins. WordPress core uses it to output a lot of good functionality such as relational links to your RSS and ATOM feeds into the head of the document. Joseph Scott wrote about this nearly a year ago. His post is fairly short but does a good job at explaining why it is important to include these functions.
Back to the original discussion, which was how do we detect whether or not wp_head and wp_footer are called in the active theme, and if called are they called, was it from the proper locations?
In my proof of concept plugin, we hook into admin_init, which will actually use wp_remote_get() to retrieve the frontend of our WordPress site. It calls the url with 2 query vars, that if present will cause the plugin to hook into wp_head and wp_footer and output some content that we will later look for. If the response was successful, as in returning a 200 response code, we will look at the content to see if <!--wp_head--> and <!--wp_footer--> are present. If they are not we will see an admin notice telling us which problems were found. If those strings were found but they were not found directly before </head> or </body> the notice will alert you of such.
Without further adieu:
Just in case you cannot see the code above, use this link: http://gist.github.com/378450.
News,Plugins,Release,Shadowbox,Support,WordPress
3 April 2010 0 Comments
This release of Shadowbox JS has been a long time coming and I am extremely happy to announce its release. With the upstream final release of shadowbox.js 3.0 came a lot of changes to the way this plugin had to work. The shadowbox.js file is now built on the fly and if possible cached to wp-content/uploads/shadowbox-js/. In the event that the file cannot be cached it will be built on the fly and delivered via admin-ajax.php with appropriate JS caching headers.
Other notable features:
- More filters for overriding numerous URLs, including shadowbox.js and shadowbox.css
- Require at least WordPress 2.8
- Remove support for Ext and Dojo
- Addition of new sub plugin titled “Shadowbox JS – Use Title from Image”, which will grab the title attribute from the child
<img> tag if it exists and push it onto the parent <a> tag if a title does not exist.
If you run into any bugs please use the Shadowbox JS support forum for problems or questions with this plugin. Support questions will be ignored if left as comments on my site, through my contact form or by email. The only supported location for support questions is http://wordpress.org/tags/shadowbox-js.
Astronomy,Books,Fun,Holidays,Movies,Science,Technology,WordPress,π
14 March 2010 1 Comment
I’ve gotten into this bad habit of not writing about anything except WordPress on this site. It’s quite sad in a way that I have this great publishing platform and I only write about WordPress, and I do so very little.
Many years ago, I don’t remember how many exactly, I was challenged by my High School math teacher, that if I could memorize all the digits of π that were on the poster (86) above the white board, that I would get an ‘A’ on the final without having to take it. I spent a week or two, I even wrote a program for the TI-83 to help me learn it. In the end I learned somewhere around 280 digits of π and got that ‘A’.
From then until now, I have always held a special place in my heart for this number of numbers. I own the movie π, I own the book a history of π and I have spent the last eleven to twelve years incredibly interested in this number. Back in 1998 or so I actually ran a site dedicated to π on geocities that is now long gone and forgotten.
So in keeping with the color scheme of that old site I used to run, which I now realize was very Matrix-esque, have a happy π day!

Happy π day!
PS: From my days as an astrophysics major, I was taught that really only the first 42 digits of π are useful for computational purposes. But what fun is that!? Keep learning and cranking out those digits of π!