2017 © Pedro Peláez
 

yii2-component yii2-gearman

Yii2 component for gearman

image

miserenkov/yii2-gearman

Yii2 component for gearman

  • Wednesday, December 14, 2016
  • by miserenkov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Yii2 gearman

This extension built on this and this. The goal of the project is opportunity of starting multiple worker processes on one machine., (*1)

Installation

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": {
       "miserenkov/yii2-gearman": "dev-master"
    }
}

Configuration

'components' => [
  'gearman' => [
      'class' => 'miserenkov\gearman\Gearman',
      'servers' => [
          ['host' => '127.0.0.1', 'port' => 4730],
      ],
      'user' => 'www-data',
      'jobs' => [
          'syncCalendar' => [
              'class' => 'common\jobs\SyncCalendar'
          ],
          ...
      ]
  ]
],
...
'controllerMap' => [
    'gearman' => [
        'class' => 'miserenkov\gearman\controllers\GearmanController',
        'gearmanComponent' => 'gearman'
    ],
    ...
],

Job example

namespace common\jobs;

use miserenkov\gearman\JobBase;

class SyncCalendar extends JobBase
{
    public function execute(\GearmanJob $job = null)
    {
        // Do something
    }
}

Manage workers

yii gearman/start 1 // start the worker with unique id
yii gearman/restart 1 // restart worker
yii gearman/stop 1 // stop worker

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

The Versions

14/12 2016

dev-master

9999999-dev

Yii2 component for gearman

  Sources   Download

MIT

The Requires

 

The Development Requires

by Misha Serenkov

yii2 queue gearman