diff --git a/composer.lock b/composer.lock index 3bf6500..e774389 100644 --- a/composer.lock +++ b/composer.lock @@ -709,16 +709,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.10.5", + "version": "v4.11.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4432ba399e47c66624bc73c8c0f811e5c109576f" + "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4432ba399e47c66624bc73c8c0f811e5c109576f", - "reference": "4432ba399e47c66624bc73c8c0f811e5c109576f", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/fe14cf3672a149364fb66dfe11bf6549af899f94", + "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94", "shasum": "" }, "require": { @@ -759,9 +759,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.5" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.11.0" }, - "time": "2021-05-03T19:11:20+00:00" + "time": "2021-07-03T13:36:55+00:00" }, { "name": "openlss/lib-array2xml", @@ -3419,16 +3419,16 @@ }, { "name": "symfony/string", - "version": "v5.3.2", + "version": "v5.3.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "0732e97e41c0a590f77e231afc16a327375d50b0" + "reference": "bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/0732e97e41c0a590f77e231afc16a327375d50b0", - "reference": "0732e97e41c0a590f77e231afc16a327375d50b0", + "url": "https://api.github.com/repos/symfony/string/zipball/bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1", + "reference": "bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1", "shasum": "" }, "require": { @@ -3482,7 +3482,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.3.2" + "source": "https://github.com/symfony/string/tree/v5.3.3" }, "funding": [ { @@ -3498,7 +3498,7 @@ "type": "tidelift" } ], - "time": "2021-06-06T09:51:56+00:00" + "time": "2021-06-27T11:44:38+00:00" }, { "name": "textalk/websocket", diff --git a/psalm.xml b/psalm.xml index 39c8ab6..aa72fc4 100644 --- a/psalm.xml +++ b/psalm.xml @@ -13,8 +13,11 @@ + + + diff --git a/src/WebSocket/Adapter/Swoole.php b/src/WebSocket/Adapter/Swoole.php index bee073f..28c4be1 100644 --- a/src/WebSocket/Adapter/Swoole.php +++ b/src/WebSocket/Adapter/Swoole.php @@ -26,6 +26,9 @@ public function __construct(string $host = '0.0.0.0', int $port = 80) parent::__construct($host, $port); $this->server = new Server($this->host, $this->port); + + // Set maximum connections to Swoole's limit of 1 Million + $this->config['max_connection'] = 1_000_000; } public function start(): void @@ -42,16 +45,18 @@ public function shutdown(): void public function send(array $connections, string $message): void { foreach ($connections as $connection) { - if ($this->server->exist($connection) && $this->server->isEstablished($connection)) { - $this->server->push( - $connection, - $message, - SWOOLE_WEBSOCKET_OPCODE_TEXT, - SWOOLE_WEBSOCKET_FLAG_FIN | SWOOLE_WEBSOCKET_FLAG_COMPRESS - ); - } else { - $this->server->close($connection); - } + go(function () use ($connection, $message) { + if ($this->server->exist($connection) && $this->server->isEstablished($connection)) { + $this->server->push( + $connection, + $message, + SWOOLE_WEBSOCKET_OPCODE_TEXT, + SWOOLE_WEBSOCKET_FLAG_FIN | SWOOLE_WEBSOCKET_FLAG_COMPRESS + ); + } else { + $this->server->close($connection); + } + }); } } @@ -65,7 +70,7 @@ public function onStart(callable $callback): self $this->server->on('start', function () use ($callback) { call_user_func($callback); - Process::signal(2, function () { + Process::signal('2', function () { $this->shutdown(); }); });