title: Parallel processing in PHP - How do you do it?
body: <p>I am currently trying to implement a job queue in php. The queue will then be processed as a batch job and should be able to process some jobs in parallel.</p>
  <p>I already did some research and found several ways to implement it, but I am not really aware of their advantages and disadvantages.</p>
  <p>E.g. doing the parallel processing by calling a script several times through <code>fsockopen</code> like explained here:<br />
  <a href="http://phplens.com/phpeverywhere/?q=node/view/254" rel="noreferrer">Easy parallel processing in PHP</a></p>
  <p>Another way I found was using the <code>curl_multi</code> functions.<br />
  <a href="http://www.php.net/manual/en/function.curl-multi-exec.php" rel="noreferrer">curl_multi_exec PHP docs</a></p>
  <p>But I think those 2 ways will add pretty much overhead for creating batch processing on a queue that should mainly run on the background?</p>
  <p>I also read about <code>pcntl_fork</code> which also seems to be a way to handle the problem. But that looks like it can get really messy if you don't really know what you are doing (like me at the moment).</p>
  <p>I also had a look at <code>Gearman</code>, but there I would also need to spawn the worker threads dynamically as needed and not just run a few and let the gearman job server then sent it to the free workers. Especially because the threads should be exit cleanly after one job has been executed, to not run into eventual memory leaks (code may not be perfect in that issue).<br />
  <a href="http://gearman.org/index.php?id=getting_started" rel="noreferrer">Gearman Getting Started</a></p>
  <p>So my question is, how do you handle parallel processing in PHP? And why do you choose your method, which advantages/disadvantages may the different methods have?</p>