Thread class for multithreading in PHP
blog.motane.lu
blog.motane.lu
Still. Having a simple library to do the fork dance and provide some synchronization between subprocesses can be very helpful for, say, long-running import scripts. At least that's what I actually consider using this for.
The biggest gotcha - pcntl_fork() is not supported under Apache. Basically rendering the whole thing rather useless for most use cases.
These scripts depend on the framework being available (for example to do certain tasks in the context of a specific user, or just for configuration settings).
It's infinitely more useful to be able to actually rely on that framework in these scripts than having to recreate all the environment (or the needed parts of it) every time - especially as the framework might change and the scripts should continue to work.
This makes these scripts prime candidates to be written in the same language as the web frontend and the framework, which, unfortunately, means PHP.
By being able to easily spawn a few subprocesses from these scripts, I can make them a lot faster while still being able to rely on the standard application environment to be there for them.
I had a go at this a while ago using pcntl_fork() and shared memory messages queues to do erlang style message passing.
My implementation is kind of half assed, but it works reasonably well. http://github.com/dhotson/Phork