1 | <?php |
||
3 | class Daemon extends Module { |
||
4 | private $tasksDirResource; |
||
5 | private $serializer; |
||
6 | private $workDir; |
||
7 | public $checked = false; |
||
8 | |||
9 | function check() { |
||
|
|||
10 | $workDir = $this->workDir(); |
||
11 | $lock = fopen($workDir . '/daemon.lock', 'w+'); |
||
12 | if (flock($lock, LOCK_EX | LOCK_NB)) { |
||
13 | flock($lock, LOCK_UN); |
||
14 | fclose($lock); |
||
15 | if (function_exists('pcntl_fork') && $pid = pcntl_fork() !== -1) { |
||
16 | if ($pid) { |
||
17 | return $pid; |
||
18 | } else { |
||
19 | $this->start(true); |
||
20 | } |
||
21 | } elseif (function_exists('fsockopen')) { |
||
22 | $fp = fsockopen($_SERVER['SERVER_NAME'], |
||
23 | 80, |
||
24 | $errno, $errstr, 30); |
||
25 | $out = "GET /daemon/start HTTP/1.1\r\n"; |
||
26 | $out .= "Host: " . $_SERVER['SERVER_NAME'] . "\r\n"; |
||
27 | $out .= "Connection: Close\r\n\r\n"; |
||
28 | fwrite($fp, $out); |
||
29 | fclose($fp); |
||
30 | } elseif (function_exists('curl_init')) { |
||
31 | $ch = curl_init('http://' . $_SERVER['SERVER_NAME'] . '/daemon/start'); |
||
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
33 | curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100); |
||
34 | curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
||
35 | $content = curl_exec($ch); |
||
36 | curl_close($ch); |
||
37 | } |
||
38 | } |
||
39 | } |
||
40 | |||
41 | function start($retry = false) { |
||
73 | |||
74 | function getNextTask() { |
||
88 | |||
89 | function task($callback) { |
||
106 | |||
107 | function workDir() { |
||
115 | |||
116 | function unserialize($item) { |
||
123 | |||
124 | function serialize($item) { |
||
127 | |||
128 | function serializer() { |
||
135 | |||
136 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.