Skip to content

thegobot/php-websocket-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebSocket client

Build Status Latest Stable Version Total Downloads License

A simple WebSocket WAMP client implemented in PHP.

This is an implementation of WAMP version 1. I have not had the time to implement WAMP 2, but if you do, that would be awesome.

Requirements

This library uses PHP 5.4+.

Install

It is recommended that you install the WebSocket client library through composer.

{
    "require": {
        "gabrielbull/websocket-client": "dev-master"
    }
}

Usage

Here is an example of a simple WebSocket client:

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

About

A simple WebSocket WAMP client implemented in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%