Asynchronous WebSocket client

v1.1.3 2019-05-31 08:10 UTC

This package is auto-updated.

Last update: 2024-04-29 03:40:46 UTC


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

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


Using composer:

composer require calcinai/bolt   


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.

$loop = \React\EventLoop\Factory::create();
$dns_factory = new React\Dns\Resolver\Factory();
$resolver = $dns_factory->createCached('', $loop);

$client = new \Calcinai\Bolt\Client('ws://', $loop, $resolver);

//Most WS servers will complain/forbid if there is no origin header


$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');


Other available events are connecting, connect, disconnecting, disconnect

HTTP basic auth is also supported via the URI inf the form user:pass@host

Any feedback is most welcome