1
|
|
|
<?php |
2
|
|
|
namespace Laravoole\Wrapper; |
3
|
|
|
|
4
|
|
|
use swoole_http_server; |
5
|
|
|
|
6
|
|
|
use Laravoole\Base; |
7
|
|
|
use Exception; |
8
|
|
|
|
9
|
|
|
abstract class Swoole extends Base |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
// http://wiki.swoole.com/wiki/page/274.html |
13
|
|
|
public static function getParams() |
14
|
|
|
{ |
15
|
|
|
return [ |
16
|
|
|
'reactor_num', |
17
|
|
|
'worker_num', |
18
|
|
|
'max_request' => 2000, |
19
|
|
|
'max_conn', |
20
|
|
|
'task_worker_num', |
21
|
|
|
'task_ipc_mode', |
22
|
|
|
'task_max_request', |
23
|
|
|
'task_tmpdir', |
24
|
|
|
'dispatch_mode', |
25
|
|
|
'message_queue_key', |
26
|
|
|
'daemonize' => 1, |
27
|
|
|
'backlog', |
28
|
|
|
'log_file' => [self::class, 'getLogFile'], |
29
|
|
|
'log_level', |
30
|
|
|
'heartbeat_check_interval', |
31
|
|
|
'heartbeat_idle_time', |
32
|
|
|
'open_eof_check', |
33
|
|
|
'open_eof_split', |
34
|
|
|
'package_eof', |
35
|
|
|
'open_length_check', |
36
|
|
|
'package_length_type', |
37
|
|
|
'package_max_length', |
38
|
|
|
'open_cpu_affinity', |
39
|
|
|
'cpu_affinity_ignore', |
40
|
|
|
'open_tcp_nodelay', |
41
|
|
|
'tcp_defer_accept', |
42
|
|
|
'ssl_cert_file', |
43
|
|
|
'ssl_method', |
44
|
|
|
'user', |
45
|
|
|
'group', |
46
|
|
|
'chroot', |
47
|
|
|
'pipe_buffer_size', |
48
|
|
|
'buffer_output_size', |
49
|
|
|
'enable_unsafe_event', |
50
|
|
|
'discard_timeout_request', |
51
|
|
|
'enable_reuse_port', |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
12 |
|
public function start() |
56
|
|
|
{ |
57
|
12 |
|
$callbacks = array_merge([ |
58
|
12 |
|
'Start' => [$this, 'onServerStart'], |
59
|
12 |
|
'Shutdown' => [$this, 'onServerShutdown'], |
60
|
12 |
|
'WorkerStart' => [$this, 'onWorkerStart'], |
61
|
12 |
|
], $this->callbacks); |
62
|
12 |
|
if (isset($this->wrapper_config['swoole_ontask'])) { |
63
|
|
|
$callbacks['Task'] = $this->wrapper_config['swoole_ontask']; |
64
|
2 |
|
$callbacks['Finish'] = $this->wrapper_config['swoole_onfinish']; |
65
|
|
|
} |
66
|
12 |
|
foreach ($callbacks as $on => $method) { |
67
|
12 |
|
$this->server->on($on, $method); |
|
|
|
|
68
|
6 |
|
} |
69
|
12 |
|
return $this->server->start(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @codeCoverageIgnore |
74
|
|
|
*/ |
75
|
|
|
public function onServerStart() |
76
|
|
|
{ |
77
|
|
|
// put pid |
78
|
|
|
file_put_contents( |
79
|
|
|
$this->pid_file, |
80
|
|
|
$this->getPid() |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
12 |
|
public function onWorkerStart($serv, $worker_id) |
85
|
|
|
{ |
86
|
12 |
|
parent::prepareKernel(); |
|
|
|
|
87
|
12 |
|
$server = $this->server; |
88
|
12 |
|
$this->app->singleton('laravoole.server', function ($app) use ($server) { |
|
|
|
|
89
|
|
|
return $server; |
90
|
12 |
|
}); |
91
|
12 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @codeCoverageIgnore |
95
|
|
|
*/ |
96
|
|
|
public function onServerShutdown($serv) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
@unlink($this->pid_file); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public static function getLogFile() |
102
|
|
|
{ |
103
|
|
|
return app()->storagePath() . '/logs/laravoole.log'; |
104
|
|
|
} |
105
|
|
|
|
106
|
6 |
|
public function on($event, callable $callback) |
107
|
6 |
|
{ |
108
|
|
|
return $this->server->on($event, $callback); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function send($fd, $content) |
112
|
|
|
{ |
113
|
|
|
return $this->server->send($fd, $content); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
2 |
|
public function close($fd) |
117
|
|
|
{ |
118
|
2 |
|
return $this->server->close($fd); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getPid() |
122
|
|
|
{ |
123
|
|
|
return $this->server->master_pid; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.