并行执行多个PHP脚本,完成时得到通知
所以,这就是我想要做的 - 实际上不言自明:
So, that's what I'm trying to do - pretty self-explanatory actually :
- 启动 X 个同时"进程(每个进程都绑定到不同的 php 脚本)
- 能够说全部什么时候完成
- Initiate X 'simultaneous' processes (each bound to a different php script)
- Be able to say when all of them are finished
我已经研究了各种不同的方法,我可能会使用 exec
和后台进程.(关于这些行).
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 :
我不知道哪种方法是检查所有进程是否完成的最有效方法 (能够密切关注总体进度 - 例如 X out ofY完了,也是必须的).
重要的是时间效率,而且——显然——不会造成任何不必要的服务器过载(所以,我想任何冻结"while
循环检查实时pid
s,即使每隔一段时间,也是不可能的,对吧?)
What is important is time-efficiency, and - obviously - not causing any unnecessary server overload (so, I suppose any 'frozen' while
loop checking for live pid
s, even if at intervals, is out of the question, right?)
非常欢迎任何建议!
PS:我最初是通过从客户端开始的异步 Ajax 请求来设置这一切的,但我目前正在考虑完全迁移到非 javascript-服务器端环境.并行处理的问题仍然存在......
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...
推荐答案
您应该调查 pcntl_fork 和相关功能.这允许一个主进程形成多个子进程并被通知子进程退出状态.
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
相关文章