2017 © Pedro Peláez
 

library wrench

PHP WebSocket client/server library

image

wrench/wrench

PHP WebSocket client/server library

  • Saturday, March 31, 2018
  • by phiamo
  • Repository
  • 43 Watchers
  • 497 Stars
  • 76,156 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 351 Forks
  • 12 Open issues
  • 14 Versions
  • 20 % Grown

The README.md

Wrench

Simple WebSocket Client/Server for PHP

A simple websocket server and client package for PHP 7.1., (*1)

Installation

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

composer require wrench/wrench ~3.0

Usage

This creates a server on 127.0.0.1:8000 with one Application that listens for WebSocket requests to ws://localhost:8000/echo and ws://localhost:8000/chat:, (*3)

Server

/**
 * 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
    {
        $connection->send($data);
    }
};

// A websocket server, listening on port 8000
$server = new \Wrench\BasicServer('ws://localhost:8000', array(
    'allowed_origins' => array(
        'mysite.com',
        'mysite.dev.localdomain'
    )
));

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

Client

/**
 * 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);
$client->connect();
$client->sendData('hello');
$response = $client->receive()[0]->getPayload();
$client->disconnect();

Releases and Changelog

See the CHANGELOG for detailed information about changes between releases., (*4)

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:, (*5)

composer require wrench/wrench ~2.0

Developing

  • 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.

The Versions

31/03 2018

dev-master

9999999-dev http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

 

The Development Requires

websocket websockets hybi

02/06 2017

2.0.x-dev

2.0.9999999.9999999-dev http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

The Development Requires

websocket websockets hybi

12/02 2017

v2.0.8

2.0.8.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

The Development Requires

websocket websockets hybi

06/11 2015

v2.0.7

2.0.7.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

The Development Requires

websocket websockets hybi

06/11 2015

v2.0.7-rc1

2.0.7.0-RC1 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

The Development Requires

websocket websockets hybi

18/02 2015

v2.0.6

2.0.6.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

The Development Requires

websocket websockets hybi

18/02 2015

v2.0.6-beta

2.0.6.0-beta http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

The Development Requires

websocket websockets hybi

19/11 2014

v2.0.5

2.0.5.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

websocket websockets hybi

19/11 2014

v2.0.5-beta

2.0.5.0-beta http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

websocket websockets hybi

19/11 2014

v2.0.4

2.0.4.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

websocket websockets hybi

15/08 2014

v2.0.3

2.0.3.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

websocket websockets hybi

15/08 2014

v2.0.2

2.0.2.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3
  • ext-sockets *

 

websocket websockets hybi

15/06 2013

v2.0.1

2.0.1.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3

 

websocket websockets hybi

28/12 2012

v2.0.0

2.0.0.0 http://github.com/varspool/Wrench

PHP WebSocket client/server library

  Sources   Download

WTFPL

The Requires

  • php >=5.3

 

websocket websockets hybi