Posts Tagged “PHP”

UUID (Universally Unique Identifier) is standard (part of ISO/IEC 11578:1996) to create “universally unique” identifiers to identify objects within a system or across system boundaries. The identifiers are 128-bit in length (that’s 16 bytes) and while there really is no way to guarantee global uniqueness the probability of colissions are very small both thanks to the number of bits and the way the identifiers are created.

The UUID generation algorithms are specified in RFC4122 and I’ve created a static PHP class that implements version 1 which is time based UUID, version 4 which is truly psuedo random UUID and version 3 and 5 which are named based UUID, using either MD5 (version 3) or SHA-1 (version 5).
Read the rest of this entry »

Comments 17 Comments »

If you ever worked with threads and particular work queues you know how convenient they can be.
Have some demanding work that needs to be done but no time to do it yourself? No problem, just put it on the work queue and continue with whatever we were doing, some other thread will come along and do the dirty work for you.

Consider the following scenario. Actions and inputs from a web page triggers something that might take a (very) long time to execute and if executed during the browser session which besides annoying the user who has to wait for a page to load, might cause a time out and interrupt the processing. How do we solve this?

Read the rest of this entry »

Comments 8 Comments »

Sometimes you need to store information and settings that really doesn’t fit into any other SQL table, in these situations it’s nice to have a generic key-value driven preference system.

The preference system consists of multiple stores or trunks, each store is identified by a unique, arbitrary string and each store has multiple key-value pairs. The key-value pairs are dynamically created and flushed to database when the preference object is destroyed or when an explicit flush is requested.
Read the rest of this entry »

Comments 1 Comment »

This is an extensible object oriented wrapper around the MySQL and MSSQL (Microsoft SQL Server) interfaces provided by PHP. I’ve been using them for a while, it’s nothing new and no rocket science but others might find them useful.

Why do this at all? why just not stick with the API provided by PHP? It’s really nothing else than a more convenient way to interact with a SQL server and exposing it’s interface in a vendor natural way. Instead of writing mysql_query everywhere, one simply writes query.

Having a consistent interface will obviously help if you are using multiple types of database servers or someday would like to migrate to another SQL server (of course, weird and vendor specific SQL code could be a problem in this case). Other advantages are things like automatic disconnection on object destruction etc.

The foundation is an abstract class called SQLConnector and provides the basic interface. The class will connect to the database on creation and disconnect when the object is destroyed, it also implements __sleep and __wakeup so that it’s possible to serialize a SQL connection.

Because SQLConnector is abstract one can’t create objects directly from it, we’ll create child classes for each type of SQL-server we want to connect to. These objects will share the same interface and can be used interchangeably.
Read the rest of this entry »

Comments 1 Comment »