模式为PHP多进程? [英] Patterns for PHP multi processes?

查看:115
本文介绍了模式为PHP多进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个设计模式存在实现一些PHP流程的执行,并在一个PHP处理结果的收集?

Which design pattern exist to realize the execution of some PHP processes and the collection of the results in one PHP process?

背景:结果
我在PHP确实有许多大树(> 10000项),并且必须在其上运行递归检查。我想,以减少执行时间。

Background:
I do have many large trees (> 10000 entries) in PHP and have to run recursive checks on it. I want to reduce the elapsed execution time.

推荐答案

如果你的目标是最少的时间 - 解决方法很简单来形容,但不是简单地实现

If your goal is minimal time - the solution is simple to describe, but not that simple to implement.

您需要找到一个模式来划分工作(你不提供这方面的问题,很多信息)。

You need to find a pattern to divide the work (You don't provide much information in the question in this regard).

然后使用一个主进程,孩子做的工作。作为一个规则的进程总数使用应介于 N 2N ,其中 ñ是内核机器具有的数目。

Then use one master process that forks children to do the work. As a rule the total number of processes you use should be between n and 2n, where n is the number of cores the machine has.

假设这个数据将被存储在你可能会考虑使用非阻塞IO最大化吞吐量的文件。不这样做将会使大部分的过程中花时间等待磁盘。 PHP有 stream_select() 可以帮助你。注意,使用它是不平凡的。

Assuming this data will be stored in files you might consider using non-blocking IO to maximize the throughput. Not doing so will make most of your process spend time waiting for the disk. PHP has stream_select() that might help you. Note that using it is not trivial.

如果你决定不使用选择 - 增加的进程数可能会帮助

If you decide not to use select - increasing the number of processes might help.

在关于 PCNTL 功能:我写与他们守护进程(适当的一个与派生,改变会话ID,正在运行的用户,等...)它是最可靠的软件,我写的一个。因为它产生的工人为每一个任务,即使存在在的任务之一的一个错误,它不会影响别人。

In regards to pcntl functions: I've written a deamon with them (a proper one with forking, changing session id, the running user, etc...) and it's one of the most reliable piece of software I've written. Because it spawns workers for every task, even if there is a bug in one of the tasks, it does not affect the others.

这篇关于模式为PHP多进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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