Restoring Large MySQL Dumps

| No Comments | No TrackBacks

I'm not exactly sure what the problem is here, but when restoring some dumps I have problems which results in the message the server has gone away. This fixes it, log in to another mysql session and enter this:

set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;

It will magically now work!  

Parallel Processing with PHP

| No Comments | No TrackBacks
Try as you might there's no getting away from PHP's single threaded nature.  But when you're looking to speed up your application there may be obvious advantages to parallelising some of the tasks that you have to perform to generate a page.  Unfortunately there's no safe and easy way to handle this easily out of the box with PHP.

If you've ever tried doing this the solution you considered was using pcntl to fork child processes, and then handle the communication back to the parent process somehow.  But this is not a good idea in an Apache process, not reccomended!

The other solution is to use some kind of job processing server like from the Zend Platform (which I've actually only just found as I was writing this post).  But that seems to cost bucks, so how about trying an open source solution, introducing PTask - a parallel processing library for PHP.


PTask is built on the ZeroMQ brokerless messaging library, and uses a server to control multiple worker processes that can then be used for generic job processing.  You implement your own job processor, which is then instantiated for however many workers you configure the server for - meaning no startup time when jobs come in to be processed.

There is a simple client/server example available in the source, so give it a go and let me know if you find it useful.

iTerm Tab Names

| No Comments | No TrackBacks

I always have multiple iTerm tabs open, and found a neat way to name them easily. Add this to your bash_profile

tab() {
    export PROMPT_COMMAND='echo -ne "\033]0;'$1'\007"';
}

Then in your sessions you can set the tab name so it's clear what's what.

$> tab "some tab name"

Beautiful video

| No Comments | No TrackBacks
Just came across a new video by "The American Dollar" on last.fm.

Multiple PHP Versions with Apache

| No Comments | No TrackBacks
Sometimes you'll find that (for whatever crappy reason, supporting legacy junk apps being the most probable) you need to run multiple version of PHP on your web server.  There are a bunch of different solutions I've found people suggesting (using virtual hosts, running one as a module and one as CGI, etc...) but if you're happy running PHP as CGI then this solution may be simpler for you.

The idea is that we'll set up a "default" version of PHP which will handle all our PHP pages, but then for any particular applications that need other versions we'll handle those differently.

So, first the default setup, open httpd.conf...

ScriptAlias /php-5/ "C:/php/5.3/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php-5/php.exe"


Then we'll override this setup for each of our applications that require a specific version of PHP.

ScriptAlias /php-4.4.9/ "C:/php/4.4.9"
<Location /my/old/app>
    Action application/x-httpd-php "/php-4.4.9/php.exe"
</Location>


Easy!  No need to run multiple versions of Apache, or fight with strange configuration.

One thing you'll need to do is copy all of the DLL's from each PHP version into the root directory of that version, and of course have different php.ini's for each one, but I'm not going to go into all that config.

I've only tried this on Windows, but it should work on other platforms to.