PHP websocket server and client. Supports secure sockets.
Via Composer
$ composer require vakata/websocket
// this handler will forward each message to all clients (except the sender)
$server = new \vakata\websocket\Server('ws://127.0.0.1:8080');
$server->onMessage(function ($sender, $message, $server) {
foreach ($server->getClients() as $client) {
if ((int)$sender['socket'] !== (int)$client['socket']) {
$server->send($client['socket'], $message);
}
}
});
$server->run();
// this handler will echo each message to standard output
$client = new \vakata\websocket\Client('ws://127.0.0.1:8080');
$client->onMessage(function ($message, $client) {
echo $message . "\r\n";
});
$client->run();
Read more in the API docs
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.