apolinux/processmanager
Composer 安装命令:
composer require apolinux/processmanager
包简介
System Process Manager written in PHP
README 文档
README
Process Manager written in PHP
Controls a pool of subprocesses and send them messages using queue. This first version uses beanstalk to communicate processes.
There is a task that sends data to children through the queue. The other processes read this data from queue and process it.
The main loop waits for the children finish to end script.
Example
example of use:
<?php
use ProcessManager\Beanstalk;
use ProcessManager\QueueManager;
require_once __DIR__ . '/../vendor/autoload.php' ;
$beanstalk = new Beanstalk(['host' => 'localhost']);
$beanstalk->setTube("send-msgs");
$beanstalk->clearTube();
$beanstalk->clearConn();
$queuemngr = new QueueManager($beanstalk) ;
// consumer job
$callable_task = function($queue, $cont){
for($cont=1; $cont<=4; $cont++){
$msg = $queue->readMsg();
echo "in task $cont. msg: $msg\n" ;
}
};
$num_tasks= 3;
for($cont=1 ; $cont<=$num_tasks; $cont++){
$queuemngr->addTask( $callable_task , [$cont] );
}
// in producer job, send info to children using queue
$queuemngr->addTask(function($queuemngr){
$msg_pending = explode(" ","El amor es como la vida y la naturaleza lo es todo") ;
foreach($msg_pending as $msg) {
$queuemngr->sendMsg($msg);
}
});
// fork and run tasks
$queuemngr->run();
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-03-23