epfremme/process-queue

使用symfony进程组件和guzzle承诺实现的简单进程队列

v1.0.1 2015-12-31 20:25 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:38 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

使用symfony进程组件和guzzle承诺实现的简单限流进程队列

概览

此工具专门用于在限流队列中异步运行多个长时间运行进程。用于防止系统同时出现过多进程而造成拥塞。

用法

创建ProcessManager时可以可选地传递进程限制,如果没有提供限制,则默认为系统可用的CPU数量。

$processFactory = new ProcessFactory('pwd');
$processManager = new ProcessManager($processFactory);

$promise1 = $processManager->enqueue();
$promise2 = $processManager->enqueue(new \SplFileInfo('/path/to/working/directory'));

$promise1->then(function(Process $process) {
    // do stuff with the completed process
});

$promise2->otherwise(function(Process $process) {
    // do stuff with the failed process
});

// start the queue
$processManager->run();

安装

Composer composer require epfremme/process-queue