1. Go to this page and download the library: Download rx/websocket library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rx / websocket example snippets
$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
}
);
$server = new \Rx\Websocket\Server('127.0.0.1:9191');
$server->subscribe(function (\Rx\Websocket\MessageSubject $cs) {
$cs->subscribe($cs);
});