PHPackages                             hoa/websocket - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. hoa/websocket

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

hoa/websocket
=============

The Hoa\\Websocket library.

3.17.01.09(9y ago)421157.7k↓25%73[23 issues](https://github.com/hoaproject/Websocket/issues)[4 PRs](https://github.com/hoaproject/Websocket/pulls)6BSD-3-ClausePHP

Since Sep 16Pushed 5y ago26 watchersCompare

[ Source](https://github.com/hoaproject/Websocket)[ Packagist](https://packagist.org/packages/hoa/websocket)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-websocket/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (17)Used By (6)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/fb12519deb454748f9c49b66c0ce4b6c18c4429b68a1280469913a123601fde2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f576562736f636b65742f6d61737465722e737667)](https://travis-ci.org/hoaproject/Websocket) [![Code coverage](https://camo.githubusercontent.com/f3566491a98b12201d0d9fdd18a78ec91f16af1301737d722912c132445259a4/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f576562736f636b65742f6d61737465722e737667)](https://coveralls.io/github/hoaproject/Websocket?branch=master) [![Packagist](https://camo.githubusercontent.com/f4ccd27ad273edfd2274b57ec4392d9ba2a8eb5726c96030b2f2ee2a98cf9ece/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f776562736f636b65742e737667)](https://packagist.org/packages/hoa/websocket) [![License](https://camo.githubusercontent.com/0f2d06532be7cc0ef48c45092fcdd7c92b63ac18eca3dd82465993c59b356a88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f776562736f636b65742e737667)](https://hoa-project.net/LICENSE)

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

Hoa\\Websocket
==============

[](#hoawebsocket)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Websocket)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/websocket)

This library allows to manipulate the WebSocket protocol and proposes a server and a client. It supports two specifications [RFC6455](https://tools.ietf.org/html/rfc6455) and [Hybi](https://tools.ietf.org/wg/hybi/draft-ietf-hybi-thewebsocketprotocol/) (at the same time).

[Learn more](https://central.hoa-project.net/Documentation/Library/Websocket).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/websocket`](https://packagist.org/packages/hoa/websocket):

```
$ composer require hoa/websocket '~3.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

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](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#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://127.0.0.1:8889')
);
$websocket->on('open', function (Hoa\Event\Bucket $bucket) {
    echo 'new connection', "\n";

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

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

    return;
});
$websocket->run();
```

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

```

  var host   = 'ws://127.0.0.1:8889';
  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';
      output.appendChild(samp);

      return;
  };

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

          if (!msg) {
              return;
          }

          try {
              socket.send(msg);
              input.value = '';
              input.focus();
          } catch (e) {
              console.log(e);
          }

          return;
      }
  });

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

          return;
      };
      socket.onmessage = function (msg) {
          print(msg.data);

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

          return;
      };
  } catch (e) {
      console.log(e);
  }

```

Here we are. All sent messages are echoed.

Awecode
-------

[](#awecode)

The following awecodes show this library in action:

- [`Hoa\Websocket`](https://hoa-project.net/Awecode/Websocket.html): *why and how to use `Hoa\Websocket\Server` and `Hoa\Websocket\Client`? A simple example will illustrate the WebSocket protocol*.

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Websocket`](https://central.hoa-project.net/Documentation/Library/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: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

Related projects
----------------

[](#related-projects)

The following projects are using this library:

- [Marvirc](https://github.com/Hywan/Marvirc), A dead simple, extremely modular and blazing fast IRC bot,
- [WellCommerce](http://wellcommerce.org/), Modern e-commerce engine built on top of Symfony 3 full-stack framework.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 94% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~75 days

Total

15

Last Release

3416d ago

Major Versions

1.14.09.16 → 2.14.09.172014-09-16

2.15.08.05 → 3.16.01.112016-01-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/a410060743cec0e0d8654661b726a7a25f5888f18059d4c942a8fd9a8128f0da?d=identicon)[Hoa](/maintainers/Hoa)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (252 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (5 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (3 commits)")[![Pierozi](https://avatars.githubusercontent.com/u/5133487?v=4)](https://github.com/Pierozi "Pierozi (2 commits)")[![tomzx](https://avatars.githubusercontent.com/u/188960?v=4)](https://github.com/tomzx "tomzx (1 commits)")[![flip111](https://avatars.githubusercontent.com/u/2244480?v=4)](https://github.com/flip111 "flip111 (1 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (1 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (1 commits)")[![osaris](https://avatars.githubusercontent.com/u/125797?v=4)](https://github.com/osaris "osaris (1 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (1 commits)")

---

Tags

hoalibraryphprfc-3629rfc-3986rfc-6455websocketwebsocket-cliwebsocket-clientwebsocket-serverrfc3986clientlibraryserverwebsocketSocketrfc6455realtimehybirfc3629

### Embed Badge

![Health badge](/badges/hoa-websocket/health.svg)

```
[![Health](https://phpackages.com/badges/hoa-websocket/health.svg)](https://phpackages.com/packages/hoa-websocket)
```

###  Alternatives

[swow/swow

Coroutine-based multi-platform support engine with a focus on concurrent I/O

1.3k2.1M84](/packages/swow-swow)[phrity/websocket

WebSocket client and server

2184.1M27](/packages/phrity-websocket)[chrome-php/wrench

A simple PHP WebSocket implementation

673.7M4](/packages/chrome-php-wrench)[warriorxk/phpwebsockets

A websocket library with support for IPC using socket pairs

1225.3k](/packages/warriorxk-phpwebsockets)[hemiframe/php-websocket

PHP WebSocket server and client library

4911.0k](/packages/hemiframe-php-websocket)[sockeon/sockeon

Framework-agnostic PHP WebSocket and HTTP server library with attribute-based routing and support for namespaces and rooms.

291.3k2](/packages/sockeon-sockeon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
