A simple PHP WebSocket implementation

Installs: 1 124 945

Dependents: 3

Suggesters: 0

Security: 0

Stars: 48

Watchers: 5

Forks: 208

Open Issues: 2

v1.6.0 2024-03-17 22:37 UTC

This package is auto-updated.

Last update: 2024-04-18 11:50:13 UTC


Latest Stable Version License

A simple PHP WebSocket implementation.


The library can be installed with Composer and is available on Packagist under chrome-php/chrome:

$ composer require chrome-php/wrench

PHP 7.4-8.3 are currently supported, only.


This creates a server on with one Application that listens for WebSocket requests to ws://localhost:8000/echo and ws://localhost:8000/chat:


// An example application, that just echoes the received
// data back to the connection that sent it
$app = new class implements \Wrench\Application\DataHandlerInterface
    public function onData(string $data, \Wrench\Connection $connection): void

// A websocket server, listening on port 8000
$server = new \Wrench\BasicServer('ws://localhost:8000', [
    'allowed_origins' => [

$server->registerApplication('echo', $app);
$server->registerApplication('chat', new \My\ChatApplication());
$server->setLogger($monolog); // PSR3


// A client side example, that sends a string and will receive
// the data back to the connection that sent it
$client = new Client('ws://localhost:8000', 'http://localhost:8000');
$response = $client->receive()[0]->getPayload();


See for contribution details.


This project is licensed under the The MIT License (MIT).