PHP5.4.3 Available on (Installs fine on Ubuntu) have the PHP 5.4 series available for installation on Debian based OS’s, you can either do it manually or use my installation script I wrote to make the process easier. All you need to do is run: curl | sudo bash And it’ll do the rest for you! Feel free to just download the .sh file if you like to see it’s not malicious. Contents are below too: #! /bin/bash echo “Adding dotdeb apt repositories” echo “deb stable all” > /etc/apt/sources.list.d/dotdeb.list echo “deb-src stable all” >> /etc/apt/sources.list.d/dotdeb.list echo “deb squeeze-php54 all” >> /etc/apt/sources.list.d/dotdeb.list echo “deb-src … Continue reading

PHP 5.4 Unofficial Ubuntu apt-get available

Ondřej Surý has released apt-get’table packages for PHP 5.4 on Ubuntu.  Instructions and installation are available from . Think I’ll keep custom building for now so I get total control but for the majority of people this is better than waiting until potentially October for it to hit the official channels.

Regular Expression (Regex) For Date part extraction/array split

Needed to use this recently to create a specificity parameter for an API at work, it gives you a key/value array from an ISO date string regardless of what is actually set in the string (e.g. if you give 2011-06-07 04 you’ll get an array back as array(‘year’=>2011, ‘month’ => 6, ‘day’ => 7, ‘hour’ => 4). If you enter 2011-06-07 04:43 you’ll get: array(‘year’=>2011, ‘month’ => 6, ‘day’ => 7, ‘hour’ => 4, ‘minute’ => 43), works from just a year all the way to seconds. /** * Gets the parts of a date that are set in an … Continue reading

Automating “Implemented methods” for a web based API

In my leedsphp talk last week I mentioned making a developer (and consumers) life easier by automatically implementing the allow methods functionality that your API may expose (e.g. you call PUT on a URL that only allows GET or POST). I did have an example slide there showing how to implement but I thought I’d posted a bare bones controller here that shows how it works. abstract class ApiController extends Zend_Rest_Controller { /** * Default head action. * * @internal * @return void */ public function headAction() { ob_start(); $this->getAction(); ob_get_clean(); } /** * Default get action. * * @internal … Continue reading

#leedsphp talk slides uploaded

Finally got around to uploading my slides (sorry for the delay!) for my talk at leedsphp on Monday 18th. They are now available online at

Using SSL in RestClient

UPDATE 14/07/2012: The author of the client has released version 2.5 a short while ago and also a video for using self-signed certificates in the client. RESTClient is a great little CLI and GUI tool for testing your REST API. I recently pushed a new API up in the office and it runs over SSL. I tried to test it in the RESTClient and got a PeerNotVerified error from Java. First thing I did was go to the SSL tab in RestClient presuming I could tell it to just trust the API…apparently not. So after a bit of web scouring … Continue reading

Reset MySQL root password if you forgot it #mysql

Just had a need to reset the mysql root login password for a server, did a bit of Googling and found out this is how you do it (I work on Ubuntu so you may have to tinker with the lines slightly depending on your distribution): Stop the current MySQL instance from running: /etc/init.d/mysql stop Run mysql with –skip-grant-tables /usr/bin/mysqld_safe –basedir=/usr –datadir=/var/lib/mysql –user=mysql –pid-file=/var/run/mysqld/ –socket=/var/run/mysqld/mysqld.sock –port=3306 –skip-grant-tables & Log into mysql, straight into the mysql database mysql -u root mysql Reset the root password. UPDATE user SET Password=PASSWORD(‘newrootpassword’) WHERE User=’root’; Flush privileges flush privileges; Shut down the new running mysql. … Continue reading

Regex-fu #PHPUK2010

Good start: don’t use it unless you need to, there’s plenty of alternatives, e.g. DOMXML, str_replace, etc. Also PHP5+ has lots of filters for email validation and URL validation etc, function calls you can make rather than complex regular expressions. Regular expressions can slow down quickly due to back tracking, pattern complexity and long strings. Then the talk has become abstract, each point is prefixed with an odd statement such as “Only elephants remember everything” and “Not all matches are made in heaven” – people are getting it, but everything needs explaining before they get it! One very good point … Continue reading

#PHPUK2010 Part 2 (MySQL stuff)

Just picked up a nice tid-bit on creating a unique index on a two column table where the values in each column may be either way around but you only ever want one instance of the value in that row. So what this means is, inserting 2,1 and 1,2 for example would result in only the first of the two inserts succeeding. CREATE UNIQUE INDEX ON tablename (LEAST(col1,col2), GREATEST(col1,col2)); Also, WITH, I’ll be honest, never thought about using it to create temporary views. This is a bad example but shows the structure rather well: WITH tempView (a,b) AS ( SELECT … Continue reading

#PHPUK2010 Part 1

Josh began by using the dictionary definition of simplicity (as given by Wikipedia) pointing out that the word is often used as a derogatory statement. He then went onto “clarity of expression” and that striving for it while programming is something a lot of people do but never quite seem to achieve. He spoke of an example where a user comes to a programmer asking for a report, and the usual first reaction is “ah, you need a reporting system.” He also said that’s not always the case, at the end of the day, the user just wanted a report, … Continue reading