并行执行多个PHP脚本,并在完成时收到通知 [英] Executing multiple PHP scripts in parallel, and being notified when finished

查看:69
本文介绍了并行执行多个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中的X Y完成,也是必须的).

重要的是时间效率,并且-显然-不会引起任何不必要的服务器过载(因此,我假设对实时" pid进行任何冻结" while循环检查,即使是间隔执行一次,也是如此)问题,对吧?)

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?)

非常欢迎任何建议!

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

这篇关于并行执行多个PHP脚本,并在完成时收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆