You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ivan Enderlin 9029708078
chore(composer) Use `dev-master` dependencies.
2 years ago
Bin chore(php) Update to PHP 7. 2 years ago
Documentation Documentation: Introduce `ws://` and `wss://`. 4 years ago
Source chore(php) Update to PHP 7. 2 years ago
Test chore(php) Update to PHP 7. 2 years ago
.State Add the state of the library. 6 years ago
.gitignore Add `.gitignore` file. 4 years ago
.travis.yml chore(ci) Drop HHVM support. 2 years ago Prepare 3 years ago CI: Set up Travis. 3 years ago
composer.json chore(composer) Use `dev-master` dependencies. 2 years ago


Build status Code coverage Packagist License

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.


Help on IRC Help on Gitter Documentation Board

This library allows to manipulate the WebSocket protocol and proposes a server and a client. It supports two specifications RFC6455 and Hybi (at the same time).

Learn more.


With Composer, to include this library into your dependencies, you need to require hoa/websocket:

$ composer require hoa/websocket '~3.0'

For more installation procedures, please read the Source page.


Before running the test suites, the development dependencies must be installed:

$ composer install

Then, to run all the test suites:

$ vendor/bin/hoa test:run

For more information, please read the contributor guide.

Quick usage

As a quick overview, we propose to start a websocket server and echo messages. The class Hoa\Websocket\Server proposes six listeners: open, message, binary-message, ping, close and error. Thus:

$websocket = new Hoa\Websocket\Server(
    new Hoa\Socket\Server('ws://')
$websocket->on('open', function (Hoa\Event\Bucket $bucket) {
    echo 'new connection', "\n";

$websocket->on('message', function (Hoa\Event\Bucket $bucket) {
    $data = $bucket->getData();
    echo '> message ', $data['message'], "\n";
    echo '< echo', "\n";

$websocket->on('close', function (Hoa\Event\Bucket $bucket) {
    echo 'connection closed', "\n";


Finally, we have to write a client in HTML and Javascript:

<input type="text" id="input" placeholder="Message…" />
<hr />
<pre id="output"></pre>

  var host   = 'ws://';
  var socket = null;
  var input  = document.getElementById('input');
  var output = document.getElementById('output');
  var print  = function (message) {
      var samp       = document.createElement('samp');
      samp.innerHTML = message + '\n';


  input.addEventListener('keyup', function (evt) {
      if (13 === evt.keyCode) {
          var msg = input.value;

          if (!msg) {

          try {
              input.value = '';
          } catch (e) {


  try {
      socket = new WebSocket(host);
      socket.onopen = function () {
          print('connection is opened');

      socket.onmessage = function (msg) {

      socket.onclose = function () {
          print('connection is closed');

  } catch (e) {

Here we are. All sent messages are echoed.


The following awecodes show this library in action:

  • Hoa\Websocket: why and how to use Hoa\Websocket\Server and Hoa\Websocket\Client? A simple example will illustrate the WebSocket protocol.


The hack book of Hoa\Websocket contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project's website:

Getting help

There are mainly two ways to get help:


Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.


Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.

The following projects are using this library:

  • Marvirc, A dead simple, extremely modular and blazing fast IRC bot,
  • WellCommerce, Modern e-commerce engine built on top of Symfony 3 full-stack framework.