wyrihaximus/react-child-process-pool

管理wyrihaximus/react-child-process-messenger进程池


README

Linux Build Status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready

安装

通过Composer安装,使用以下命令,它将自动检测最新版本并将其与~绑定。

composer require wyrihaximus/react-child-process-pool

  • Dummy - 适用于测试,不执行任何操作但符合其合同
  • Fixed - 创建指定数量的工作进程
  • Flexible - 根据需要创建工作进程,给定最小和最大值,将在这些值内创建工作进程

用法

此包将wyrihaximus/react-child-process-messenger组织到池中,有关基本消息传递的详细信息,请参阅该包了解如何使用它。

创建池

此包附带一组工厂,用于创建不同的池。(以下示例中的所有选项都是默认选项。)

Dummy

创建一个Dummy

$loop = EventLoopFactory::create();

Dummy::createFromClass(ReturnChild::class, $loop)->then(function (PoolInterface $pool) {
  // Now you have a Dummy pool, which does absolutely nothing
});

Fixed

创建一个Fixed

$loop = EventLoopFactory::create();
$options = [
    Options::SIZE => 5,
];
Fixed::createFromClass(ReturnChild::class, $loop, $options)->then(function (PoolInterface $pool) {
    // You now have a pull with 5 always running child processes 
});

Flexible

创建一个Flexible

$loop = EventLoopFactory::create();
$options = [
    Options::MIN_SIZE => 0,
    Options::MAX_SIZE => 5,
    Options::TTL      => 0,
];
Flexible::createFromClass(ReturnChild::class, $loop, $options)->then(function (PoolInterface $pool) {
    // You now have a pool that spawns no child processes on start.
    // But when you call rpc a new child process will be started for 
    // as long as the pool has work in the queue. With a maximum of five.
});

CpuCoreCountFixed

创建一个大小设置为CPU核心数的Fixed

$loop = EventLoopFactory::create();

CpuCoreCountFlexible::createFromClass(ReturnChild::class, $loop)->then(function (PoolInterface $pool) {
    // You now have a Fixed pool with a child process assigned to each CPU core.
});

CpuCoreCountFlexible

以下示例将创建一个最大大小设置为CPU核心数的灵活池。其中,create方法要求您提供React\ChildProcess\ProcesscreateFromClass允许您传递一个实现WyriHaximus\React\ChildProcess\Messenger\ChildInterface的类的名称,该类将用作客户端的工作进程。请参阅WyriHaximus\React\ChildProcess\Messenger\ReturnChild以了解其工作方式。

$loop = EventLoopFactory::create();

CpuCoreCountFlexible::createFromClass(ReturnChild::class, $loop)->then(function (PoolInterface $pool) {
    // You now have a Fixed pool with a child process assigned to each CPU core,
    // which, just like the Flexible pool, will only run when there is something
    // in the queue.
});

许可证

版权所有 2017 Cees-Jan Kiewiet

特此授予任何获得此软件及其相关文档文件(“软件”)副本的任何人免费使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许提供软件的人做同样的事,前提是以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论此类责任是基于合同、侵权或其他方式,源于、因之或与此软件或软件的使用或其他交易有关。

提交日志之外的贡献者

  • Gabi Davila - 帮助测试我的github令牌在AppVeyor上发起拉取请求的安全性