Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple PHP WebSocket WAMP client
branch: master

This branch is 10 commits ahead, 56 commits behind lemmingzshadow:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

WebSocket client

Build Status

A simple WebSocket WAMP client implemented in php.

Requirements

This library uses PHP 5.3+.

Install

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

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

Usage

Here is an example of a simple WebSocket client:

class Client implements WebSocketClient\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();
Something went wrong with that request. Please try again.