Sivel.net  Throwing Hot Coals


Rocky Roads Ahead

Over the next 2 months (or thereabout), expect things to not always work exactly as they may now on my site. Some things unrelated to the actual install of WordPress on my site may be unavailable during this time. I don’t think anyone other than myself uses them, so I think everything should mostly go unnoticed.

I’m going to be performing some shuffling, and hope to keep it as minimally impacting as possible.

If you spot something strange, give me a shout!

Fun News WordPress

WordPress Metric Comparison of 2.9.2 and 3.0

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.

Code CoolStuff Fun PHP WordPress

Detect wp_head and wp_footer from a Plugin

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://paste.sivel.net/24.

CoolStuff Fun HowTo PHP Plugins Questions Uncategorized WordPress

Happy Pi Day

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 pi 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 pi 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 pi, I own the book a history of pi 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 pi 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 pi day!

pi

Happy pi day!

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

Astronomy Books Fun Holidays Movies Science Technology WordPress Pi

Where&#8217;d the CSS Go?

So I’m bored…Bored of a lot of things. So to satisfy at least part of my boredom, I killed my CSS a few minutes ago. Of course I have a backup, and yes I did kill it on purpose. Maybe someday I will restore it. My boredom isn’t driving me to rewrite my CSS, but destroying my CSS makes me smile, which seems to help. UPDATE: I just wrote a script to restore 10 lines of my css every 10 minutes. In about 11 hours the site should be back to normal. Perhaps I’ll write a script that continually removes all of the lines and then restores them all, 10 lines at a time. Wouldn’t that be interesting?

Asides Bored Fun General Rant