Skip to content

Commit 04e8b8a

Browse files
authored
Merge pull request #275 from ecmchow/master
Corrected Socket.php and improve README
2 parents a5758da + 708afb9 commit 04e8b8a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
A server side alternative implementation of [socket.io](https://github.com/socketio/socket.io) in PHP based on [Workerman](https://github.com/walkor/Workerman).<br>
33

44
# Notice
5-
Only support socket.io v1.3.0 or greater. <br>
5+
Only support socket.io >= v1.3.0 and <= v2.x <br>
66
This project is just translate socket.io by [workerman](https://github.com/walkor/Workerman).<br>
7-
More api just see http://socket.io/docs/server-api/
7+
More api just see [https://socket.io/docs/v2/server-api/](https://socket.io/docs/v2/server-api/)
88

99
# Install
1010
composer require workerman/phpsocket.io
@@ -138,6 +138,28 @@ $io->on('connection', function ($connection) use ($io) {
138138
Worker::runAll();
139139
```
140140

141+
## Acknowledgement callback
142+
```php
143+
144+
use Workerman\Worker;
145+
use PHPSocketIO\SocketIO;
146+
147+
require_once __DIR__ . '/vendor/autoload.php';
148+
149+
$io = new SocketIO(2021);
150+
151+
$io->on('connection', function ($connection) use ($io) {
152+
$socket->on('message with ack', function ($data, $callback) use ($socket, $io) {
153+
// acknowledgement callback
154+
if ($callback && is_callable($callback)) {
155+
$callback(0);
156+
}
157+
});
158+
});
159+
160+
Worker::runAll();
161+
```
162+
141163
# 手册
142164
[中文手册](https://github.com/walkor/phpsocket.io/tree/master/docs/zh)
143165

src/Socket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public function onack($packet)
346346
call_user_func($ack, $packet['data']);
347347
unset($this->acks[$packet['id']]);
348348
} else {
349-
echo ('bad ack '. packet.id);
349+
echo ('bad ack '. $packet['id']);
350350
}
351351
}
352352

0 commit comments

Comments
 (0)