Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

multithreading - Executing multiple PHP scripts in parallel, and being notified when finished

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...