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

MySQL and Binary(16) – The Reasons/Benefits/Drawbacks (#mysql)

I recently posted an article about using BINARY(16) for storing MD5’s as unique identifiers instead of simple integer ID’s (usually auto increment); in that article I touched on one of the benefits, reducing JOIN’s, but there are other reasons for doing it too, so I thought I’d post an article discussing purely the reasons behind using BINARY(16). As I discussed in my previous article, an MD5 string is actually a hexadecimal number capable of storing values as large as 340,282,366,920,938,463,463,374,607,431,768,211,456. MySQL doesn’t have any efficient integer field for storing numbers this big so you have two choices for storage, a … Continue reading

MySQL – Binary(16) and scalability

Over the past few months at work, we’ve seen our database grown from silly big to really silly big, it’s still a way to go to get to the size of the big boys such as Facebook etc. but it’s still a database stored in MySQL that most day-to-day PHP programmers would avoid like a midget cannibal. One of the great things about using something like MySQL (and any other “real” database) is the ability to cross-query data, i.e. to grab data from one data-set (table) and join it to another data-set (table) to get a single set of results, … Continue reading

Superb VPS (Virtual Private Server) Provider – VPS.net Review

A few months ago at work we realised the need for lots of “nodes” (servers) in the UK and in the US initially. We have a lot of data processing that we need to do and we worked out it would be faster and cheaper if we could distribute the work over lots of servers rather than a few beefy servers. Dan started looking around and found VPS.net, they looked good so we thought we’d give them a go. Of course we didn’t want to “put all our eggs in one basket” so we took out some VPS servers with … Continue reading