-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.md~
98 lines (82 loc) · 2.19 KB
/
README.md~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
yii2-gearman
============
This extension built on [this](https://github.com/Filsh/yii2-gearman) and [this](https://github.com/sinergi/gearman) and [this](https://github.com/shakura/yii2-gearman)
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](http://getcomposer.org/). To do so, add the following lines to your ``composer.json`` file.
```json
{
"require": {
"ferrumfist/yii-gearman": "dev-master"
}
}
```
## Configuration
```php
'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
```php
namespace common\jobs;
use micmorozov\yii2-gearman\JobBase;
class SyncCalendar extends JobBase
{
public function execute(\GearmanJob $job = null)
{
// Do something
}
}
```
## Manage workers
```cmd
yii gearman/start // start the worker
yii gearman/restart // restart worker
yii gearman/stop // stop worker
```
## Example using Dispatcher
```php
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](http://supervisord.org/) 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
```