dev-master
9999999-dev https://github.com/shakura/yii2-gearmanGearman handler for PHP
MIT
The Requires
- php >=5.4.0
- yiisoft/yii2 *
- react/event-loop 0.4.*
- psr/log ~1
The Development Requires
by Waclaw Shakura
extension yii
Gearman handler for PHP
This extension built on this and this. The goal of the project is opportunity of starting multiple worker processes on one machine., (*1)
It is recommended that you install the Gearman library through composer. To do so, add the following lines to your composer.json
file., (*2)
{ "require": { "shakura/yii2-gearman": "dev-master" } }
'components' => [ 'gearman' => [ 'class' => 'shakura\yii2\gearman\GearmanComponent', 'servers' => [ ['host' => '127.0.0.1', 'port' => 4730], ], 'user' => 'www-data', 'jobs' => [ 'syncCalendar' => [ 'class' => 'common\jobs\SyncCalendar' ], ... ] ] ], ... 'controllerMap' => [ 'gearman' => [ 'class' => 'shakura\yii2\gearman\GearmanController', 'gearmanComponent' => 'gearman' ], ... ],
namespace common\jobs; use shakura\yii2\gearman\JobBase; class SyncCalendar extends JobBase { public function execute(\GearmanJob $job = null) { // Do something } }
yii gearman/start 1 // start the worker with unique id yii gearman/restart 1 // restart worker yii gearman/stop 1 // stop worker
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
[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
Gearman handler for PHP
MIT
extension yii