From bbe82593759b7bdb2be151afea9b9415f93e02a5 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 7 Jul 2021 17:27:45 +0200 Subject: [PATCH 1/4] fix(swoole): send messages non-blocking --- src/WebSocket/Adapter/Swoole.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/WebSocket/Adapter/Swoole.php b/src/WebSocket/Adapter/Swoole.php index bee073f..2d29095 100644 --- a/src/WebSocket/Adapter/Swoole.php +++ b/src/WebSocket/Adapter/Swoole.php @@ -42,16 +42,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); + } + }); } } From 4c77e73f704ddc8e0ace5041ff3e310d84b68024 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 9 Jul 2021 17:09:26 +0200 Subject: [PATCH 2/4] fix(swoole): maximum connections config --- src/WebSocket/Adapter/Swoole.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/WebSocket/Adapter/Swoole.php b/src/WebSocket/Adapter/Swoole.php index 2d29095..602f95a 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 From a51a2f4c391429f2ec2769467eedce526d9ede28 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 9 Jul 2021 17:22:22 +0200 Subject: [PATCH 3/4] fix(psalm): add more stubs --- composer.lock | 24 ++++++++++++------------ psalm.xml | 3 +++ 2 files changed, 15 insertions(+), 12 deletions(-) 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 @@ + + + From 9b741619cfd50558b11f24c5bc47308b18a23617 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 9 Jul 2021 17:24:09 +0200 Subject: [PATCH 4/4] fix process signal method --- src/WebSocket/Adapter/Swoole.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSocket/Adapter/Swoole.php b/src/WebSocket/Adapter/Swoole.php index 602f95a..28c4be1 100644 --- a/src/WebSocket/Adapter/Swoole.php +++ b/src/WebSocket/Adapter/Swoole.php @@ -70,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(); }); });