1
|
|
|
<?php |
2
|
|
|
namespace Laravoole\Wrapper; |
3
|
|
|
|
4
|
|
|
use Garveen\FastCgi\FastCgi; |
5
|
|
|
use swoole_server; |
6
|
|
|
|
7
|
|
|
class SwooleFastCGIWrapper extends Swoole implements ServerInterface |
8
|
|
|
{ |
9
|
|
|
protected $max_request = 0; |
10
|
|
|
protected $request_count = 0; |
11
|
|
|
|
12
|
4 |
|
public function __construct($host, $port) |
13
|
|
|
{ |
14
|
4 |
|
$this->server = new swoole_server($host, $port); |
15
|
4 |
|
} |
16
|
|
|
|
17
|
4 |
|
public function start() |
18
|
|
|
{ |
19
|
4 |
|
if (!empty($this->handler_config)) { |
20
|
4 |
|
if (isset($this->handler_config['max_request'])) { |
21
|
4 |
|
$this->max_request = $this->handler_config['max_request']; |
22
|
2 |
|
} |
23
|
4 |
|
$this->handler_config['max_request'] = 0; |
24
|
4 |
|
$this->server->set($this->handler_config); |
|
|
|
|
25
|
2 |
|
} |
26
|
|
|
|
27
|
4 |
|
$this->callbacks = array_merge([ |
28
|
4 |
|
'Receive' => [$this, 'onReceive'], |
29
|
4 |
|
], $this->callbacks); |
30
|
|
|
|
31
|
4 |
|
return parent::start(); |
32
|
|
|
} |
33
|
|
|
|
34
|
4 |
|
public function onReceive($serv, $fd, $from_id, $data) |
35
|
|
|
{ |
36
|
4 |
|
return $this->fastcgi->receive($fd, $data); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
4 |
|
public function requestCallback($psrRequest) |
40
|
|
|
{ |
41
|
4 |
|
return $this->onPsrRequest($psrRequest); |
42
|
|
|
} |
43
|
|
|
|
44
|
4 |
|
public function sendCallback($fd, $payload) |
45
|
|
|
{ |
46
|
4 |
|
$this->server->send($fd, $payload); |
|
|
|
|
47
|
4 |
|
} |
48
|
|
|
|
49
|
4 |
|
public function closeCallback($fd) |
50
|
|
|
{ |
51
|
4 |
|
$this->server->close($fd); |
|
|
|
|
52
|
4 |
|
if ($this->max_request) { |
53
|
4 |
|
if ($this->request_count++ > $this->max_request) { |
54
|
|
|
$this->server->stop(); // @codeCoverageIgnore |
55
|
|
|
} |
56
|
2 |
|
} |
57
|
|
|
|
58
|
4 |
|
} |
59
|
|
|
|
60
|
4 |
|
public function onWorkerStart($serv, $worker_id) |
61
|
|
|
{ |
62
|
4 |
|
fwrite(STDOUT, "Swoole worker $worker_id starting\n"); |
63
|
4 |
|
parent::onWorkerStart($serv, $worker_id); |
64
|
4 |
|
$this->fastcgi = new FastCgi([$this, 'requestCallback'], [$this, 'sendCallback'], [$this, 'closeCallback'], function ($level, $info) { |
65
|
4 |
|
fwrite(STDOUT, "$level $info"); |
66
|
4 |
|
}); |
67
|
|
|
// override |
68
|
4 |
|
config(['laravoole.base_config.deal_with_public' => false]); |
69
|
4 |
|
} |
70
|
|
|
} |
71
|
|
|
|
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.