lowerpower/bolt
Asynchronous WebSocket client built on ReactPHP
Maintainers
Requires
- clue/block-react: ^1.2
- react/child-process: ^0.5.0
- react/datagram: ^1.1
- react/dns: ^0.4.11
- react/event-loop: ^0.4
- react/http: ^0.7.2
- react/http-client: ^0.5
- react/promise: ^2.5
- react/promise-timer: ^1.2
- react/socket: ^0.8
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 9b5fecc7faba4af2abff757a1f102e4674699a58
- Michael Calcinai <michael.woop@calcin.ai>
- Mike Johnson
This package is not auto-updated.
Last update: 2026-06-24 12:18:24 UTC
README
Asynchronous WebSocket client client library for PHP. Supports HyBi, (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.
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.
Installation
Using composer:
"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.
$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
HTTP basic auth is also supported via the URI inf the form user:pass@host
Any feedback is most welcome
