1. Go to this page and download the library: Download gavroche/websocket-client 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/ */
gavroche / websocket-client example snippets
use WebSocketClient\WebSocketClient;
use WebSocketClient\WebSocketClientInterface;
class Client implements WebSocketClientInterface
{
private $client;
public function onWelcome(array $data)
{
}
public function onEvent($topic, $message)
{
}
public function subscribe($topic)
{
$this->client->subscribe($topic);
}
public function unsubscribe($topic)
{
$this->client->unsubscribe($topic);
}
public function call($proc, $args, Closure $callback = null)
{
$this->client->call($proc, $args, $callback);
}
public function publish($topic, $message)
{
$this->client->publish($topic, $message);
}
public function setClient(WebSocketClient $client)
{
$this->client = $client;
}
}
$loop = React\EventLoop\Factory::create();
$client = new WebSocketClient(new Client, $loop);
$loop->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.