netlogix/jobqueue-pool 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

netlogix/jobqueue-pool

Composer 安装命令:

composer require netlogix/jobqueue-pool

包简介

Hold a pool of subprocesses to execute jobs in

README 文档

README

This package runs jobs (immplements \Flowpack\JobQueue\Common\Job\JobInterface) in \React\ChildProcess\Process and provides a \React\EventLoop\LoopInterface to do some work in the parent process while waiting for the children to complete.

<?php
use Netlogix\JobQueue\Pool\Pool;

Pool::create(
    outputResults: true,
    async: false,
    preforkSize: 1
)
    ->runLoop(function(Pool $pool) {

        $process = $pool->runJob(new VeryLongRunningJob());

        $process->on('success', function(int $exitCode) {
            echo 'success' . PHP_EOL;
        });

        $process->on('error', function(int $exitCode, $errorMessageStream) {
            echo 'failed: ' . $exitCode . PHP_EOL;
            echo stream_get_contents($errorMessageStream);
        });

        $process->on('exit', function() use ($pool) {
            if (count($pool) === 0) {
                $pool->eventLoop->stop();
            }
        });

        $pool->eventLoop->addTimer(5, function() use ($process) {
            $process->stdin->write('hello!' . PHP_EOL);
        });

        $pool->eventLoop->addPeriodicTimer(function() {
            // ping parent database connections while children are working
        });
    });

Arguments:

Output results:

<?php
use Netlogix\JobQueue\Pool\Pool;

Pool::create(outputResults: true)
    ->runLoop(function(Pool $pool) {
        $process = $pool->runJob($job);
        $process->on('exit', fn() => $pool->eventLoop->stop());
    });

Links stdout of the child process to stdout of the parent process and stderr of the child process to stderr of the parent process.

This is close to what \Neos\Flow\Core\Booting\Scripts::executeCommand() does, with our implementation actually differentiate between stdout and stderr while Neos\Flow passes everything to stdout.

This can be done manually to do some processing of the given streams:

<?php
use Netlogix\JobQueue\Pool\Pool;

Pool::create(outputResults: false)
    ->runLoop(function(Pool $pool) {
        $process = $pool->runJob($job);
        $process->stdout->on('data', fn($chunk) => fputs(\STDOUT, $chunk));
        $process->stderr->on('data', fn($chunk) => fputs(\STDOUT, $chunk));
        $process->on('exit', fn() => $pool->eventLoop->stop());
    });

Running all child processes asynchronously:

<?php
use Netlogix\JobQueue\Pool\Pool;

Pool::create(async: true)
    ->runLoop(function(Pool $pool) {
        $pool->runJob($job);
    });

It is possible to run child processes asynchronously, although this means there is no stdout and stderr connection from the child to the parent.

Start worker children although no task is available

<?php
use Netlogix\JobQueue\Pool\Pool;

Pool::create(preforkSize: 3)
    ->runLoop();

Creates a set number of worker children in advanced without assigning a queue name or a job payload to them.

This will allow for the children to boot up and e.g. warm singleton instances up.

We don't provide any useful warmup code here, so add e.g. advices yourself.

Custom loop object

<?php
use Netlogix\JobQueue\Pool\Pool;

$loop = \React\EventLoop\Loop::get();

Pool::create(eventLoop: $loop)
    ->runLoop();

Just in case there other code already created a running event loop, which is possible in theory but not very likely.

netlogix/jobqueue-pool 适用场景与选型建议

netlogix/jobqueue-pool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 94.9k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 netlogix/jobqueue-pool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 netlogix/jobqueue-pool 我们能提供哪些服务?
定制开发 / 二次开发

基于 netlogix/jobqueue-pool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 94.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-30