Archive for category PHP
Fast PHP array_unique for removing duplicates
Posted by Howard Yeend in PHP on June 21, 2010
PHP’s native dedupe function, array_unique, can be slow for large amount of input. Here I’m going to talk about a simple function that performs the same task but which runs a lot faster.
Often, people spout PHP optimisation advice that is incredibly misguided, so I want to make it clear up-front that you should be benchmarking your scripts using xdebug before you start optimising, and very often the real bottlenecks cannot be avoided by using “micro-optimization”. Here’s a nice PDF on Common Optimization Mistakes.
Now I’ve got that disclaimer out of the way, I believe it’s OK to talk about making a faster array_unique because it’s often used on large amounts of data – for example removing duplicate email addresses, and as such there are genuine use cases for a fast array_unique in PHP. Also our fast_unique function can be several seconds faster than array_unique so we’re not necessarily talking about micro-optimisation here; on 200k duplicate entries, array_unique takes nearly 5 seconds on my windows dev box, fast_unique takes <1 second on the same data. On 2 million entires the results are staggering – performance graphs are given below (but then, why are you doing that kind of work in PHP?).
The function looks like this:
Read the rest of this entry »
Fast PHP – effective optimisation and bottleneck detection
Posted by Howard Yeend in PHP, Productivity, web on April 18, 2010
PHP is not the fastest language on earth. That honour probably goes to machine code. But like many high-level languages, PHP provides some handy abstractions, like named variables, hashmaps (associative arrays), a C-like syntax, object oriented capabilities, loose typing and so on – we trade processing speed for development ease.
So it’s quite a common problem that people find their large PHP web applications running quite slowly.
Here are some frequently encountered bottlenecks found in web applications generally, and PHP specifically:
Super Useful Web Dev Tools
Posted by Howard Yeend in Firefox, PHP, Productivity, Programs, javascript on March 17, 2010
OMG, it’s been a whole month since my last update.
I have draft posts about all kinds of Good Stuff™, but none are quite publishable yet. So today I’m just going to point you at a few great resources I use all the time while doing my web development magic:
allRGB Entry – PHP Image Manipulation
Posted by Howard Yeend in PHP on February 10, 2010
The objective of allRGB is simple: To create images with one pixel for every rgb-color (16777216 to be exact); not one color missing, and not one color twice.
What a cool project! As regular readers will know, I love messing about with image manipulation in PHP, so when I heard about the allRGB project I knew I had to make an entry for it. A few false starts and about half an hour later, I proudly submitted my first entry, a 4096×4096 PNG image containing every single possible RGB colour. As one redditor put it, “It’s like poetry, just without words.”

Click for the high resolution (only 173Kb)
And now on to the code:
Read the rest of this entry »
Textpad PHP manual lookup tool
Posted by Howard Yeend in PHP, Productivity on February 1, 2010
A little tip for those of us using textpad to develop in PHP. How often do you find yourself having to go back to PHP.net to check up on a function – is it ($needle, $haystack) or ($haystack, $needle)? I can never remember! With this tool I just need to highlight the function in textpad, press Ctrl-1 and up pops php.net in a new tab, opened on that function’s manual entry. Neat huh?
Here’s how:
GIFexplode – community powered web development
Posted by Howard Yeend in PHP, web on August 2, 2009
Let me share with you a very cool story about strangers coming together and building something.
I was browsing reddit yesterday, and I saw a thread entitled “Someone needs to make a Firefox add-on that lets you step through animated gifs frame by frame“. I thought “hey that’s a nice well defined simple idea” – just the kind of thing I love, so I registered a nice-sounding domain name and started looking at how to use PHP to split an animated gif into its component frames – I figured it couldn’t be too hard. Read the rest of this entry »
Howard Yeend – UK Web Developer – PHP CV
Posted by Howard Yeend in (misc), PHP on August 1, 2009
Northampton / howard.yeend@gmail.com / 07790 816291
Availability
Not currently seeking work. Sorry! (updated Aug 2010)
PHP error handling
Posted by Howard Yeend in PHP on July 5, 2009
Does this type of error handling code look familiar?
function doFunction($var) { if(is_numeric($var)) { /* do some stuff*/ } else { return -1; } }
BLEH. How ugly is that? There’s no indication whether -1 is actually an error or a valid return value, or what it means. And other functions might use false to indicate errors so there’s inconsistency. So I’ve written a very simple function to help you give meaningful PHP error messages.
Read the rest of this entry »
PHP 5.3.0 Released!
Posted by Howard Yeend in PHP on July 1, 2009
If you’re still stuck in the old PHP 4 days, please please please take today’s release of PHP 5.3.0 as your cue to start learning about the wonderful world of object oriented PHP 5.
5.3.0 isn’t a hugely interesting release, but getting your PHP4 code compatible with 5 will ease the process when PHP 6 comes along. PHP6 is really where it’s at:
What’s out:
No more register_globals (finally)
No more magic_quotes (you kinda liked magic quotes? Admittedly it was handy, but when you think about it, having code that may or may not be sanitised depending on a php.ini setting is a Bad Idea™)
No more HTTP_GET_VARS and cousins. Just change to $_GET etc and you’re fine.
What’s in:
A bunch of minor fixes aaand:
Namespaces – so we can section off bits of code properly. Woohoo! more info here.
Short post today I know, but I’ve got some real coding to do :) If you’re not doing anything better, go download PHP and have a play with it.
Google Images Link Improver WordPress Plugin
Posted by Howard Yeend in PHP, Wordpress on May 1, 2009
Google Images Link Improver improves the way visitors find your site by redirecting hits from google images to more relevant content on your blog.
Here’s an example of how it works on an actual google images result for “earthrise”. The user clicks the following images result:
… and here’s how the clickthrough page looks:
![]() Before Plugin Installation |
![]() After Plugin Installation |




