Taking out the trash – unset and wp_cache_flush to free up memory

I’ve been working on a third party API plugin for WordPress that requires a script that auto updates from the API. It consists of pulling a big list of items from the API and checking them against the local site entries, often adding new items or updating existing entries.
The problem was with a number of memory allocation errors with PHP as the script went on, often about half way through the execution. Memory exhausted and Fatal Allowed memory issues popping up. A memory limit change would fix the problem to a point, it would still leave issues though – to work through the full list of items would need a very high PHP memory limit and also what happens if the list gets bigger in future? When 64Mb stops being enough do we simply up it to 128Mb what about when that isn’t enough do we carry on upping it? That still leaves a period where errors are being thrown and updates are missed until it is picked up and the memory limit is upped.

I made sure I called wordpress without themes to reduce a little bit of load and a quick check through to make sure unset() was being used as it should be – I’ll admit my code discipline has been lax in the past with regards to this but as ever we are always learning and making sure that we can improve our techniques. Unsetting things properly to free up the memory is one of those things I now make sure I’m doing rather than just overwriting old variables.
So the script was unsetting as it should and with diligent debugging with php memory usage outputs it became apparent that it was around WordPress functions that the memory usage was going up and not being unset, gradually leading to the errors. Plenty of looking around and eventually I stumbled upon wp_cache_flush and it worked a treat – every time I went around a processing loop or finished a process I called the cache flush and it removed all the stuff WordPress had been storing. I’m sure this wouldn’t be the best fix all for every situation but it’s certainly something to be well aware of.

The site gets a new look

Kamikaze Music old design
If you’ve made your way to the site since last night you’ll have seen the new look (a picture of the old one is above if you can’t remember it). I’m not sure if it would be classed as a redesign or realign, but it’s the biggest overhaul I’ve done in a while. I had a few new things I wanted to try out and I had some ideas that had sat around for ages, plus the site was seeming a little sluggish so I got stuck into it and decided to get it done at the weekend.
Continue reading

The Blonde Board

The Blonde Board is a personal project that has long been in need of a revamp.

Started after a bit of fun at university the web site aims to collect together examples of all the daft things people say.

Having intially worked with a custom CMS (Content Management System) the redesign moved the site onto the wordpress platform with a custom theme.

The Design

The main focus of the theme was to keep things simple and easily readable as the site is heavily text based.
To add a bit of visual interest drop caps were added to the main body of text on each entry making use of a font devlivered by the TypeKit service.

CSS3 and Typekit

The theme makes use of new CSS3 properties and animation. Currently only viewable in webkit based web browsers (Safari and Chrome) the animation of a
stickman dunce character is made when hovering over menu items on the main navigation.

The use of non web safe fonts delivered from TypeKit enable the drop caps to be styled without using image replacment techniques and are also used on the
main site navigation.

Details

  • Word press site with custom theme
  • Full design and coding of theme
  • Use of new CSS3 and TypeKit font replacement
  • Site live at http://www.theblondeboard.com
  • Preview image
  • Preview image
  • Preview image