micmorozov/yii-gearman
Composer 安装命令:
composer require micmorozov/yii-gearman
包简介
Gearman handler for PHP (fork)
关键字:
README 文档
README
This extension built on this and this and this The goal of the project is opportunity of starting multiple worker processes on one machine. Work only as process(fork). In config you can set count of nodes, look 'Configuration'
Installation
It is recommended that you install the Gearman library through composer. To do so, add the following lines to your composer.json file.
{
"require": {
"ferrumfist/yii-gearman": "dev-master"
}
}
Configuration
'components' => [ 'gearman' => [ 'class' => 'ferrumfist\yii\gearman\src\GearmanComponent', 'servers' => [ ['host' => '127.0.0.1', 'port' => 4730], ], 'user' => 'www-data', 'jobs' => [ 'syncCalendar' => [ 'class' => 'common\jobs\SyncCalendar', 'count'=>10 // default count 1 ], ... ] ] ], ... 'controllerMap' => [ 'gearman' => [ 'class' => 'ferrumfist\yii\gearman\src\GearmanController', 'gearmanComponent' => 'gearman', ], ... ],
Job example
namespace common\jobs; use ferrumfist\yii-gearman\JobBase; class SyncCalendar extends JobBase { public function execute(\GearmanJob $job = null) { // Do something } }
Example using Dispatcher
Yii::app()->gearman->getDispatcher()->background('syncCalendar', new JobWorkload([ 'params' => [ 'data' => 'value' ] ])); // run in background Yii::app()->gearman->getDispatcher()->execute('syncCalendar', new JobWorkload([ 'params' => [ 'data' => 'value' ] ])); // run synchronize
Example of Supervisor config to manage multiple workers
[program:yii-gearman-worker]
command=php [path_to_your_app]/yii gearman/start %(process_num)s
process_name=gearman-worker-%(process_num)s
priority=1
numprocs=5
numprocs_start=1
autorestart=true
统计信息
- 总下载量: 577
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-28