2017 © Pedro Peláez
 

library bolt

Asynchronous WebSocket client built on ReactPHP

image

lowerpower/bolt

Asynchronous WebSocket client built on ReactPHP

  • Friday, October 20, 2017
  • by lowerpower
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

bolt

Asynchronous WebSocket client client library for PHP. Supports HyBi, ~~as well as Hixie #76~~ (no point)., (*1)

This was built purely to be a client, as the majority of the WS clients available also contain servers and are very bloated., (*2)

This is not the original version, this has been updated to use latest reactphp and the API has been modified to be more consistant with modern reactphp., (*3)

Installation

Using composer:, (*4)

"require": {
    "lowerpower/bolt": "^0.2"
}    

Usage

Since this really lends itself to being an asynchronous app, it is built to use the React event loops and resolver since there's a good chance they'll be in your project already and this lets you attach to the same loop., (*5)

$loop = \React\EventLoop\Factory::create();

// other options like tls, socket, etc are possible see "React\Socket\Connector"
$options=$options=array(
    'timeout'=>5.0                      /* 'timeout'=> false for disable */
);

// Now workes exaction like "React\Socket\Connector" 
$client = new \Calcinai\Bolt\Client($loop, $options);

//Most WS servers will complain/forbid if there is no origin header
$client->setOrigin('127.0.0.1');

// new, URL is here, ws:// and wss:// supported
$client->connect('ws://127.0.0.1:1337/chat');

$client->on('stateChange', function($newState){
    echo "State changed to: $newState\n";
});

$client->on('message', function($message) use ($client){
    echo "New message: \n";
    echo $message;

    $client->send('This is a response message');
});

$loop->run();

Other available events are connecting, connect, closing, close, (*6)

HTTP basic auth is also supported via the URI inf the form user:pass@host, (*7)

Any feedback is most welcome, (*8)

The Versions

01/12 2015

v0.1.4

0.1.4.0

Asynchronous WebSocket client

  Sources   Download

MIT

The Requires

 

by Michael Calcinai

01/12 2015

v0.1.3

0.1.3.0

Asynchronous WebSocket client

  Sources   Download

MIT

The Requires

 

by Michael Calcinai

22/10 2015

v0.1.2

0.1.2.0

Asynchronous WebSocket client

  Sources   Download

MIT

The Requires

 

by Michael Calcinai

20/10 2015

v0.1.1

0.1.1.0

Asynchronous WebSocket client

  Sources   Download

MIT

The Requires

 

by Michael Calcinai

16/10 2015

v0.1.0

0.1.0.0

Asynchronous WebSocket client

  Sources   Download

MIT

The Requires

 

by Michael Calcinai