1

So, that's what I'm trying to do - pretty self-explanatory actually :

  • Initiate X 'simultaneous' processes (each bound to a different php script)
  • Be able to say when all of them are finished

I've had a look at various different approaches, and I'm probably going to use exec and background processes. (Something along these lines).

The thing - which I really can't get my head around - is :

I can't figure out which is the most efficient way to check whether ALL of the processes are finished (being able to keep an eye on the general progress - e.g. X out of Y finished, is also a must).

What is important is time-efficiency, and - obviously - not causing any unnecessary server overload (so, I suppose any 'frozen' while loop checking for live pids, even if at intervals, is out of the question, right?)

ANY suggestions are very much welcome!


P.S.: I've initially set this whole thing up with asynchronous Ajax requests starting from the client-side, but I'm currently considering a migration to a non-javascript fully-server-side environment. The issue with parallel-processing though remains...

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223

1 Answers1

3

You should investigate the pcntl_fork and related functions. This allows one master process to form a number of child processes and be notified of child exit status.

http://php.net/manual/en/function.pcntl-fork.php

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • 1
    As mike says forking is by far your best bet. I wrote an article about this a long time ago with sample code that you can use. I used it for sending out a huge list of text messages with forking, but you can use it for what you are doing: http://jservedio.com/article/3 – Jack Jul 31 '12 at 21:23