I’ve been researching how to best write a long running PHP script executed on the command-line, and whilst there are Linux commands you can use to daemonise a command, these can also be written into a php script as well.

The easiest way to daemonise a command on a posix system is to run:

nohup command < /dev/null > /dev/null 2>&1 &

This simply calls nohup to execute the command, which in effect disables the SIGHUP signal (used to tell a child its parent terminal is closing), and backgrounds the process. All standard file descriptors are set to /dev/null to stop the command from reading/outputting anything back to the terminal, and so that when the terminal is closed, reads and writes from stdin/stdout/stderr do not fail.

This is a bit clunky, but the same can be achieved in PHP either by default, or via a command-line argument.
Read the rest of this entry »

Ibuildings, a PHP development company with offices in the Netherlands, UK and Italy, have been running a series of challenges, with prizes such as iPads and tickets to the Dutch PHP Conference (DPC, of which they host). The latest completed challenge, the Elephpant challenge, was in the form of a code contest to write the fastest, shortest and least complex algorithm in PHP to solve a Travelling Salesman problem.

I’m happy to say that I was one of the winners for this task, getting 30 points (10 in each scoring method), which was the maximum points possible, for the medium category (people with 2 to 4 years experience), and winning a ticket to the DPC.

Here I will describe the two solutions I researched and completed. I only submitted the one which I thought would give me the biggest chance of winning, but each had their own specialities.

Read the rest of this entry »

OData is a new API protocol that has recently been released by Microsoft, along with the launch of their new site on the 16th March 2010. It is a RESTful standard, which adds a lot of its own goods to the table.

As a RESTful standard, it exposes a web service in the form of resources accessible via discrete HTTP urls, representing actions via the HTTP methods. It fills in the gaps that the REST style of architecture leaves open, giving a full specification, from the request to the response (although omitting authentication and authorisation). OData surprisingly also allows RPC-style operations as well.

In essence, OData is as to RESTful service style as SOAP is to RPC. Before this, I had a hard time taking REST seriously, given the lack of protocol specifications meaning that each implementation of a RESTful service tends to handle things differently.

Read the rest of this entry »

Here are several techniques for creating a secure shared web server.

Update 2010-03-14 – Revised opinion about APC and eAccellerator, which possibly do use memory-mapped files, also added detail about mpm_worker not working with mod_apparmor.

Read the rest of this entry »

If you’ve ever searched for a WordPress theme on WordPress.org, you’ve probably found that none of them are suitable for your personal blog. Most tend to be complex designs that you’re sure someone created with a specific look in mind, but they don’t suit you.

A friend from work, Louise (now departed to another warren), mentioned something similar almost 6 months ago, so when she tweeted a suggestion to design something like the Posterous look (it’s a very nice simple but popular look), I offered to help, figuring it would take no time at all to create something similar in WordPress.

Read the rest of this entry »

First up, there is no silver bullet in building a web service infrastructure. There are two prevailant types, however, that you should ideally be choosing from:

  • RPC (remote procedure call) – e.g. SOAP, XML-RPC
  • REST (Representational state transfer) – e.g. umm? REST?

What I strongly suggest is using one of these, and not designing your own protocol, or proprietry XML straight-up. As for which you should choose…

Read the rest of this entry »

I’ve decided to split up my blog articles into two websites:

1) Webtatic.com – The currently active blog will still be home to all my projects, and blog posts will be results-orientated, generally resulting in deliverables.

Here are some of the deliverables I have or are coming up in the future:

  • Webtatic Optimizer – a CSS and Javascript file optimizer that concatenates, minifies and compresses. Features coming up are automatic uploading of optimised files to CDN’s, CSS sprites.
  • repo.webtatic.com – a YUM repository, currently having updated CentOS php, httpd and git RPMS
  • Minimous – a reproduction of the Posterous layout as a WordPress theme, also hosted on WordPress.org
  • Webtatic Platform – (not yet released) a modularised project based on Zend Framework, which Zend Framework applications can plug into to give easily installable and integrated features, one day hopefully including  CMS/SCM for developers.

2) andytson.com – This blog will instead be opinion-orientated or guides, and may not always be technical, though I have plans for many posts already.

Some topics I have planned:

  • PHP code distribution (svn/git, pear/pyrus)
  • Web development tools (Zend Studio/PDT, LAMP/WAMP)
  • Development process best practices (versioning, unit-testing, continuous integration etc)
  • Development implementation (DBAL, ActiveRecord, ORM, Web Services, PHP 5.3)
  • Domain-driven development and Service-Orientated Architecture.

Some of these I had planned to write almost 3 years ago, but I hope to make sure I post more frequently.

Recently I have been handling the security of some sensitive data. I had originally been encrypting/decrypting data with a symmetric-key system using mcrypt for PHP. This was due to the web frontend and the backend existing on the same server. However for security purposes I am now separating the frontend and backend onto different servers, so that there is no way the web accessible frontend, whether compromised or not, can get at the data it inserts into the database.

In order to do this, a asymmetric-key system is needed, such as public-key cryptography. Googling for examples of this in PHP, there doesn’t seem to be any results of this other than the php OpenSSL extension documentation, and systems that try to reinvent the wheel with their own implementations.

Using the PHP OpenSSL extension it is fairly easy to sort out a secure system for encrypting data with one key that only can be decrypted with another.
Read the rest of this entry »

Regular savers are a great way for people new to saving (who have already used up their ISA allowance), to start saving some of their income. They can usually offer attractive interest rates with per month maximum deposits.

To existing savers however they might not seem that attractive, with the per month maxiumum deposits being so low. However when the difference between the person’s instant saver and regular saver rate is large enough, the gains may be worth it.

Read the rest of this entry »