并行执行多个PHP脚本,完成时得到通知

2023-07-16php开发问题
2

本文介绍了并行执行多个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 循环检查实时pids,即使每隔一段时间,也是不可能的,对吧?)

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脚本,完成时得到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17