-
Notifications
You must be signed in to change notification settings - Fork 2
/
Module.php
76 lines (69 loc) · 2.1 KB
/
Module.php
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
<?php
/**
* @author Yurko Fedoriv <yurko.fedoriv@gmail.com>
*/
namespace gearman;
/**
* Application module that contains all gearman related components.
* Provides default config for all of them. Components config may be overrided in config file. e.g.
* modules => array('gearman' => array('class' => '\gearman\Module', 'components' => array('client' => array('servers' => '172.16.1.111:4730'))))
*
* Components:
*
* @property Client $client
* @property Worker $worker
* @property Server $server
* @property MemCache $cache
*/
class Module extends \CModule
{
/**
* @var WorkerCommand Currently running worker command instance.
*/
public $command;
/**
* @var string Server to which all components should connect by default
*/
public $host = '127.0.0.1';
/**
* Initailizes component, also merges runtime configuration with default one.
*
* @return void
*/
public function init() {
parent::init();
$this->setComponents(\CMap::mergeArray($this->defaultComponentsConfig(), $this->getComponents(false)), false);
}
/**
* Provides default configuration for gearman components. Uses host property
*
* @return array
*/
protected function defaultComponentsConfig() {
return array(
'client' => array(
'class' => '\gearman\Client',
'servers' => $this->host . ':4730'
),
'worker' => array(
'class' => '\gearman\Worker',
'servers' => $this->host . ':4730',
'options' => array(GEARMAN_WORKER_GRAB_UNIQ),
),
'server' => array(
'class' => '\gearman\Server',
'server' => $this->host . ':4730'
),
'cache' => array(
'class' => '\gearman\MemCache',
'keyPrefix' => 'gearman',
'servers' => array(
array(
'host' => $this->host,
'port' => 11211,
),
)
)
);
}
}