cSprites for PHP 5.3.1/2

Joost posted a great article on reducing http requests on WordPress sites recently and one comment caught my attention. Nabil mentioned cSprites. It’s a WordPress plugin that merges the images in your posts into one file and uses CSS to position the single merged file in place of the original images. Here’s a good post explaining how this technique works.

Unfortunately it hasn’t been updated in over a year, and the current version doesn’t work if you have PHP 5.3.2 (and probably 5.3.1) as it trips over this PHP bug. The fix is simple, get rid of call_user_func_array() and call the functions directly.

I had it installed here and it worked well enough but not perfectly. Here’s the post I made on the plugin’s support forum if anyone’s interested.

I don’t think the author will update the plugin again and in fact he’s looking for someone else to take over. Anyone?

The plugin has been running on my photoblog for the last hour ago and I haven’t noticed any problems yet. As a bonus, it also stops people right clicking and stealing saving my photos for their own use. I’ve since removed it as visitors were only seeing blank images. Oh well.

So, want to give a “fixed version” a go? Grab csprites-for-wordpress.zip and install it in the usual way. Support queries should be directed towards the plugin support forum. ;)

Oh yeah, there’s also the SpriteMe bookmarklet if you don’t want to go fiddling with WordPress plugins!

Notes when upgrading to PHP5

I upgraded one of my servers to PHP5 this morning. Two things to watch out for:

  • The location of your php.ini may have changed. It’s probably now in /etc/php5/apache2/. You need to copy over any changes from your old one.
  • Update your libraries too such as the mysql client and the gd library. Don’t forget you can delete the old ones. apt-get install php5-mysql php5-gd will do the job of installing, the old packages have a php4 prefix.
  • WP-Cache doesn’t like PHP5 much. If you see a blank page after upgrading to PHP5, then hit reload and it loads, then WP-Cache needs to be modified. Leroy has the fix, open wp-cache-phase2.php in your wp-cache folder and change ob_end_clean() to ob_end_flush(). SImple as that!

The reason for the upgrade? I wanted to install the gd extension, but after lots of fun upgrading everything my browser tried to download every page, complaining that it was a phtml file. I chose the upgrade to PHP5 to fix it!

And finally, the reason for gd, was to get the heatmap in this wordpress click tracking plugin working. It’s like Crazy Egg and it works well, but I couldn’t get it to display a heatmap for any page other than the front page. Some of the comments on Daily Blog Tips where I found it are hilarious. They completely miss the point of using a heatmap!