Senior developer for Inviqa based in Sheffield. I spend most of my time trying to be a better developer and make things simpler. For fun I like to make PHP do things it shouldn’t like calculating pi to thousands of places and generating fractals. Outside of work three young children take up most of my time but I occasionally manage to get out cycling.
Fork it! Parallel processing in PHP
Most computers these days have more than one processor or core. Why then do we normally only use one of them at a time to run our PHP processes? Furthermore, how can we use PHP to write long running background processes. PHP has process control support in unix environments through the PCNTL extension. Running multiple PHP processes can lead to some unexpected behaviour so there are a few patterns to follow to avoid the pitfalls. Once you have multiple PHP processes running you will probably want to make them talk to each other. We will look at the various techniques for inter process communication. Finally we will look at what turns out to be the hardest part of parallel scripts namely thinking about your problems in a parallel way. I will try and offer some tips on how to start doing this and go about getting more work done at the same time.