2017 © Pedro Peláez
 

yii2-extension yii2-gearman

Gearman handler for PHP (fork)

image

micmorozov/yii2-gearman

Gearman handler for PHP (fork)

  • Tuesday, April 10, 2018
  • by micmorozov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 154 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 28 Forks
  • 1 Open issues
  • 2 Versions
  • 157 % Grown

The README.md

yii2-gearman

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', (*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": {
       "micmorozov/yii2-gearman": "dev-master"
    }
}

Configuration

'components' => [
  'gearman' => [
      'class' => 'micmorozov\yii2\gearman\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' => 'micmorozov\yii2\gearman\GearmanController',
        'gearmanComponent' => 'gearman',
    ],
    ...
],

Job example

namespace common\jobs;

use micmorozov\yii2-gearman\JobBase;

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

Manage workers

yii gearman/start  // start the worker
yii gearman/restart  // restart worker
yii gearman/stop // 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

10/04 2018

dev-master

9999999-dev https://github.com/micmorozov/yii2-gearman

Gearman handler for PHP (fork)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Morozov

extension yii

26/07 2016

dev-ChildControl

dev-ChildControl https://github.com/vov4ik08/yii2-gearman

Gearman handler for PHP (fork)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yaroslav Spirin

extension yii