|
@@ -95,7 +95,7 @@ discard block |
|
|
block discarded – undo |
|
95
|
95
|
$this->buildMessageProcessor(); |
|
96
|
96
|
|
|
97
|
97
|
// Some optimization |
|
98
|
|
- \gc_enable(); // As the process never stops, the garbage collector will be usefull, you may need to call it manually sometimes for performance purpose |
|
|
98
|
+ \gc_enable(); // As the process never stops, the garbage collector will be usefull, you may need to call it manually sometimes for performance purpose |
|
99
|
99
|
\set_time_limit(0); // It's by default on most server for cli apps but better be sure of that fact |
|
100
|
100
|
} |
|
101
|
101
|
|
|
@@ -105,13 +105,13 @@ discard block |
|
|
block discarded – undo |
|
105
|
105
|
*/ |
|
106
|
106
|
public function setMessageHandler($messageHandler, $uri = '*') |
|
107
|
107
|
{ |
|
108
|
|
- if (!$messageHandler instanceof MessageHandlerInterface && !\is_string($messageHandler)) { |
|
|
108
|
+ if (!$messageHandler instanceof MessageHandlerInterface && !\is_string($messageHandler)) { |
|
109
|
109
|
throw new \InvalidArgumentException('The message handler must be an instance of MessageHandlerInterface or a string.'); |
|
110
|
110
|
} |
|
111
|
111
|
if (\is_string($messageHandler)) { |
|
112
|
112
|
try { |
|
113
|
113
|
$reflection = new \ReflectionClass($messageHandler); |
|
114
|
|
- if(!$reflection->implementsInterface('Nekland\Woketo\Message\MessageHandlerInterface')) { |
|
|
114
|
+ if (!$reflection->implementsInterface('Nekland\Woketo\Message\MessageHandlerInterface')) { |
|
115
|
115
|
throw new \InvalidArgumentException('The messageHandler must implement MessageHandlerInterface'); |
|
116
|
116
|
} |
|
117
|
117
|
} catch (\ReflectionException $e) { |
|
@@ -135,7 +135,7 @@ discard block |
|
|
block discarded – undo |
|
135
|
135
|
$this->loop = $this->loop ?? \React\EventLoop\Factory::create(); |
|
136
|
136
|
$this->server = $this->server ?? new \React\Socket\Server($this->loop); |
|
137
|
137
|
|
|
138
|
|
- $this->server->on('connection', function ($socketStream) { |
|
|
138
|
+ $this->server->on('connection', function($socketStream) { |
|
139
|
139
|
$this->onNewConnection($socketStream); |
|
140
|
140
|
}); |
|
141
|
141
|
$this->server->listen($this->port); |
|
@@ -150,7 +150,7 @@ discard block |
|
|
block discarded – undo |
|
150
|
150
|
*/ |
|
151
|
151
|
private function onNewConnection(ConnectionInterface $socketStream) |
|
152
|
152
|
{ |
|
153
|
|
- $connection = new Connection($socketStream, function ($uri, Connection $connection) { |
|
|
153
|
+ $connection = new Connection($socketStream, function($uri, Connection $connection) { |
|
154
|
154
|
return $this->getMessageHandler($uri, $connection); |
|
155
|
155
|
}, $this->loop, $this->messageProcessor); |
|
156
|
156
|
|