MyTetra Share
Делитесь знаниями!
Время создания: 22.05.2018 18:00
Текстовые метки: php websocket packagist
Раздел: WebSocket
Запись: Velonski/mytetra-database/master/base/1526994008m85ixqhgv7/text.html на

Simple WebSocket Client/Server for PHP

Latest Stable Version

Latest Unstable Version

Build Status


A simple websocket server and client package for PHP 7.1.


The library is PSR-4 compatible, with a vendor name of Wrench. It's available on Composer as wrench/wrench, so you can:

composer require wrench/wrench ~3.0


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', array(

'allowed_origins' => array(





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


Releases and Changelog

See the CHANGELOG for detailed information about changes between releases.

PHP5 Support

The latest major release dropped support for PHP versions prior to 7.1. If you need support for older versions of PHP, see the 2.0 branch. The latest 2.0 branch release is 2.0.8. You can install it with:

composer require wrench/wrench ~2.0


Run ./vendor/bin/phpcs and fix any errors that you come across

Run ./vendor/bin/phpunit --exclude-group large,medium for a fast test between changes

See Also

Ratchet an excellent Websocket layer for React.

Так же в этом разделе:
MyTetra Share v.0.59
Яндекс индекс цитирования