-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.class.php
More file actions
50 lines (41 loc) · 982 Bytes
/
worker.class.php
File metadata and controls
50 lines (41 loc) · 982 Bytes
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
<?php
abstract class Worker
{
protected $config;
public function __construct($config)
{
$this->config = $config;
$this->running = true;
$this->after_construct();
}
public function start()
{
$this->register_signals();
$this->run();
$this->shutdown();
}
protected function run()
{
while ($this->running) {
pcntl_signal_dispatch();
$this->run_cycle();
}
}
protected function stop()
{
$this->running = false;
}
protected function after_construct() { }
protected function after_register_signals() { }
protected function before_shutdown() { }
abstract protected function run_cycle();
protected function register_signals()
{
pcntl_signal(SIGTERM, array(&$this, "stop"));
$this->after_register_signals();
}
protected function shutdown()
{
$this->before_shutdown();
}
}