From 2b4a47d131b738eaf530badab2c896ddde434556 Mon Sep 17 00:00:00 2001 From: Eric Chow <88537011+ecmchow@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:53:38 +0800 Subject: [PATCH 1/2] added acknowledgement example --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86546fc..d54328f 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ A server side alternative implementation of [socket.io](https://github.com/socketio/socket.io) in PHP based on [Workerman](https://github.com/walkor/Workerman).
# Notice -Only support socket.io v1.3.0 or greater.
+Only support socket.io >= v1.3.0 and <= v2.x
This project is just translate socket.io by [workerman](https://github.com/walkor/Workerman).
-More api just see http://socket.io/docs/server-api/ +More api just see [https://socket.io/docs/v2/server-api/](https://socket.io/docs/v2/server-api/) # Install composer require workerman/phpsocket.io @@ -138,6 +138,28 @@ $io->on('connection', function ($connection) use ($io) { Worker::runAll(); ``` +## Acknowledgement callback +```php + +use Workerman\Worker; +use PHPSocketIO\SocketIO; + +require_once __DIR__ . '/vendor/autoload.php'; + +$io = new SocketIO(2021); + +$io->on('connection', function ($connection) use ($io) { + $socket->on('message with ack', function ($data, $callback) use ($socket, $io) { + // acknowledgement callback + if ($callback && is_callable($callback)) { + $callback(0); + } + }); +}); + +Worker::runAll(); +``` + # 手册 [中文手册](https://github.com/walkor/phpsocket.io/tree/master/docs/zh) From 708afb91ca19e7bc1ea92f25a4f2330354cfff71 Mon Sep 17 00:00:00 2001 From: Eric Chow <88537011+ecmchow@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:53:50 +0800 Subject: [PATCH 2/2] corrected object --- src/Socket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket.php b/src/Socket.php index d3cd322..6ca0424 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -346,7 +346,7 @@ public function onack($packet) call_user_func($ack, $packet['data']); unset($this->acks[$packet['id']]); } else { - echo ('bad ack '. packet.id); + echo ('bad ack '. $packet['id']); } }