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上的pull请求安全性