rx / websocket
Websockets for PHP using Rx
Installs: 178 022
Dependents: 5
Suggesters: 0
Security: 0
Stars: 34
Watchers: 5
Forks: 9
Open Issues: 6
Requires
- ratchet/rfc6455: ^0.3
- react/event-loop: ^1.2
- react/http: 1.5.* | 1.6.* | 1.7.* | 1.8.*
- reactivex/rxphp: ^2.0.1
Requires (Dev)
- phpunit/phpunit: ^9 | ^10
README
Rx\Websocket is a PHP Websocket library.
Usage
Client
$client = new \Rx\Websocket\Client('ws://127.0.0.1:9191/'); $client->subscribe( function (\Rx\Websocket\MessageSubject $ms) { $ms->subscribe( function ($message) { echo $message . "\n"; } ); $sayHello = function () use ($ms) { $ms->onNext('Hello'); }; $sayHello(); \EventLoop\addPeriodicTimer(5, $sayHello); }, function ($error) { // connection errors here }, function () { // stopped trying to connect here } );
An Echo Server
$server = new \Rx\Websocket\Server('127.0.0.1:9191'); $server->subscribe(function (\Rx\Websocket\MessageSubject $cs) { $cs->subscribe($cs); });
Server that dumps everything to the console
$server = new \Rx\Websocket\Server('127.0.0.1:9191'); $server->subscribe(function (\Rx\Websocket\MessageSubject $cs) { $cs->subscribe(function ($message) { echo $message; }); });
Installation
Using composer:
composer require rx/websocket