https://github.com/moodrain/websocket-php
implement websocket protocol with php
https://github.com/moodrain/websocket-php
Last synced: 3 months ago
JSON representation
implement websocket protocol with php
- Host: GitHub
- URL: https://github.com/moodrain/websocket-php
- Owner: moodrain
- Created: 2021-09-22T08:21:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-17T06:30:23.000Z (over 3 years ago)
- Last Synced: 2025-01-13T18:18:17.064Z (5 months ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### WebSocket-PHP
```
$server = new Server();$server->on('open', function(Connection $client) use ($server) {
echo 'client connect, id: ' . $client->id() . ' total count: ' . count($server->clients()), PHP_EOL;
});$server->on('close', function(Connection $client) use ($server) {
echo 'client close , id: ' . $client->id() . ' total count: ' . count($server->clients()), PHP_EOL;
});$server->on('message', function(Connection $client, Message $message) use ($server) {
$server->sendMessage($client, \Muyu\WebSocket\Packet::MSG_TYPE_TXT, 'get ' . $message->content());
});$server->on('send', function(Connection $client, Message $message) use ($server) {
echo 'client id ' . $client->id() . ' send ' . $message->content(), PHP_EOL;
});$server->start();
```