镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
vakataPublic

About

PHP websocket server & client

Resources

Contributing

Stars

45 stars

Watchers

5 watching

Forks

Latest commit

 

History

36 Commits

Folders and files

Repository files navigation

websocket

Latest Version on Packagist Software License

PHP websocket server and client. Supports secure sockets.

Install

Via Composer

$ composer require vakata/websocket

Server usage

// 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 ($client !== $sender) {
            $client->send($message);
        }
    }
});
$server->run();

Client usage

// 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->connect();

Usage in HTML

var sock = new WebSocket('ws://127.0.0.1:8080/');
sock.send("TEST");

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

PHP websocket server & client

Resources

Contributing

Stars

45 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages