PHP

Posts about the server side scripting language PHP

Bookmarklet To Run XDebug Profiler

5th February 2013 - 2 minutes read time
XDebug is a great PHP debugging tool, but it also comes with a very useful profiler that can tell you all sorts of information about your PHP application. This includes things like memory footprint and CPU load but will also have detailed information about the entire callstack of the code that was run. To enable the profiler part of XDebug you just need to set up a few rules in your xdebug.ini file.

Xdebug Debugging On A Remote Server

20th January 2013 - 3 minutes read time

I have started to use virtual machines to develop sites rather than installing a local web server. This allows me to replicate the exact setup of the server I will be deploying to with ease. For each virtual machine I set up a shared folder which allows me to store the files locally whilst being able to run the code on the virtual machine. One thing I missed was the ability to use xdebug to debug the sites through Netbeans, so I set about trying to set up the virtual hosts to allow me to use xdebug remotely.

All that is needed was to add a xdebug.remote_connect_back clause to the xdebug.ini file found in the PHP configuration. Set this value to 1 to automatically connect back to any xdebug session that is created on the server.

Automating Headless Selenium PHPUnit Tests

15th January 2013 - 7 minutes read time

I have talked before about running Selenium tests in PHPUnit but I have only recently come to properly automate things. Getting a Selenium server to start and stop in a script is relatively easy and can be done in a simple script. My original script for running a directory of PHPUnit tests was as follows. I will explain more about how this all works later on in this post.

Storing Automated YSlow Tests With Show Slow

3rd December 2012 - 8 minutes read time

I was at a meeting of the Manchester Web Performance Group the other day where Tom Taylor gave a talk about some of the performance testing tool he uses at Laterooms.com. He used a ruby script to set up some preferences in Firefox which then ran Selenium to open some web pages and test them with YSlow. The results of the YSlow inspection are then sent to a Show Slow server where the results can be graphed over time. I realise that I've just mentioned a whole stack of technologies there, so let me pick out the important ones:

Selenium is a remote control agent for web browsers, although it is most stable in Firefox. I have written about this tool before but it allows us to automate interaction with a website via a series of selenium scripts. These scripts can be exported into different code formats, including PHP.

Playing With ReactPHP

19th November 2012 - 14 minutes read time

I recently saw an implementation of a Twitter wall that used node.js to run searches on Twitter and post the results on a webpage. I had been wanting to create something using ReactPHP so I thought this was a good opportunity to have a go. ReactPHP, if you haven't heard of it, is an event-driven, non-blocking I/O that is essentially the PHP equivalent of node.js. The major difference is that ReactPHP is written in pure PHP with no extra components, whereas node.js is a collection of different programs, interfaces and languages. As a first attempt I wanted to create something simple so it needed to use simple JavaScript to load in the latest tweets for a given hashtag from a ReactPHP server. I have to warn that this is a simplistic implementation of ReactPHP, but it shows the basics of how to get started.

Happy Birthday PHP Script

29th October 2012 - 1 minute read time

When posting happy birthday messages to developers over social media I like to write it in code, just to be geeky. The following code will print the happy birthday song using PHP.

PHPNW12: A Review

20th October 2012 - 48 minutes read time

The annual PHPNW conference gets better every year, and this year was no exception. I have been going to the PHPNW conference since their inception in 2008 and this year I was lucky enough to be involved in some of the pre-conference organising and helping out over the event.

When the call for papers ended in June I spent a weekend reading abstracts and bios of speakers to try and reduce the 169 talk submissions to around 32 sessions. I then sat down with Jeremy Coates, Rick Ogden and Jenny Wong to select which talks would be included in the final selection. Once the sessions were complete I sat down and started working on a blog schedule and wrote a few blog posts to garner attention.

Testing Websites With Selenium And PHP

16th July 2012 - 6 minutes read time

Selenium is an application that allows automated testing of websites through a browser and consists of a number of different components. It allows the creation of browser tests that perform certain actions, which can then be run again at a later date. Three components are required to allow Selenium to run tests through PHP. These are as follows:

UK PostCode Validation Function In PHP

21st May 2012 - 5 minutes read time

Creating a function to validate UK postcodes would seem like a simple task, but there is a little more to it than checking the number of characters. In fact there are several different variants of UK postal codes, especially if you include BFPO and overseas addresses. The official postcode specification details the structure of the postcode, and there is also a list of BFPO numbers from mod.uk.

PHP fgetcsv() Gotcha

19th May 2012 - 2 minutes read time

I quite often find myself with the need to pull the data from a CSV file into a system. This might be to fill out essential data like postcodes or to update a site with new content. What system I happen to be using dictates how I pull in the CSV file, but writing a quick parser is quite easy in PHP via the use of the fgetcsv() function.

Unfortunately, when using this function it is quite easy to miss something quite important and creates a quite useless piece of code. Take the following example. It appears to be fine at first glance, but the output of the code is always to run once and stop.