PHPackages                             nusje2000/websockets - 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. nusje2000/websockets

ActiveLibrary

nusje2000/websockets
====================

Websockets

0.1.1(6y ago)18[1 issues](https://github.com/nusje2000/websockets/issues)MITPHP

Since Jul 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/nusje2000/websockets)[ Packagist](https://packagist.org/packages/nusje2000/websockets)[ RSS](/packages/nusje2000-websockets/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

### Websocket server

[](#websocket-server)

Almost fully compatible with

Simple version can be found here: [https://developer.mozilla.org/en-US/docs/Web/API/WebSockets\_API/Writing\_WebSocket\_servers](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers)

#### Data framing

[](#data-framing)

The following data frame was used to parse messages from and to the clients.

```
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-------+-+-------------+-------------------------------+
|F|R|R|R| opcode|M| Payload len |    Extended payload length    |
|I|S|S|S|  (4)  |A|     (7)     |             (16/64)           |
|N|V|V|V|       |S|             |   (if payload len==126/127)   |
| |1|2|3|       |K|             |                               |
+-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
|   Extended payload length continued, if payload len == 127    |
+ - - - - - - - - - - - - - - - +-------------------------------+
|                               |Masking-key, if MASK set to 1  |
+-------------------------------+-------------------------------+
| Masking-key (continued)       |          Payload Data         |
+-------------------------------- - - - - - - - - - - - - - - - +
:                     Payload Data continued ...                :
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
|                     Payload Data continued ...                |
+---------------------------------------------------------------+

```

##### Opcodes

[](#opcodes)

hexinttextconstcontrol0x00ContinuationOpcodeEnum::CONTINUEtrue0x11TextOpcodeEnum::TEXTfalse0x22BinaryOpcodeEnum::BINfalse0x33No meaningOpcodeEnum::OPCODE\_3false0x44No meaningOpcodeEnum::OPCODE\_4false0x55No meaningOpcodeEnum::OPCODE\_5false0x66No meaningOpcodeEnum::OPCODE\_6false0x77No meaningOpcodeEnum::OPCODE\_7false0x88CloseOpcodeEnum::CLOSEtrue0x99PingOpcodeEnum::PINGtrue0xA10PongOpcodeEnum::PONGtrue0xB11No meaningOpcodeEnum::OPCODE\_11true0xC12No meaningOpcodeEnum::OPCODE\_12true0xD13No meaningOpcodeEnum::OPCODE\_13true0xE14No meaningOpcodeEnum::OPCODE\_14true0xF15No meaningOpcodeEnum::OPCODE\_15true##### Mapping

[](#mapping)

All incomming frames are being mapped to the Frame class, this class is basically an oop version of the dataframe displayed above. The following mapping is used:

- `FIN` =&gt; Frame::isFinal(): bool
- `RSV1` =&gt; none
- `RSV2` =&gt; none
- `RSV3` =&gt; none
- `OPCODE` =&gt; Frame::getOpcode(): int
- `MASK` =&gt; Frame::isMasked(): bool
- `PAYLOAD_LENGTH` =&gt; Frame::getPayloadLength(): int
- `MASKING_KEY` =&gt; Frame::getMaskingKey(): string
- `PAYLOAD_DATA` =&gt; Frame::getPayload(): string

#### Additional functionallity

[](#additional-functionallity)

There are a few functions added to the Frame for ease of use:

- **Frame::isClosing(): bool** =&gt; is true when opcode = `0x8`
- **Frame::isControl(): bool** =&gt; is true when opcode is for contol
- **Frame::isNonControl(): bool** =&gt; is true when opcode is not for contol

#### Events

[](#events)

The websocket makes use of the symfony event dispatcher. Because of this, each incomming dataframe wil dispatch an event. This event can be used to react on incomming frames. The following is a list of events that can be listened to:

Event classReasonHandshakeEventfirst data sent over a new connection will be treated as handshake requestConnectEventnew connection (handshake is already done when this event is triggered)DataEventreceived data (triggered when data is received)FrameEventreceived frame (triggered when a frame is received)MessageEventreceived message (only works when the FrameEventSubscriber is an active listener, triggered when a frame is received with TEXT opcode)DisconnectEventdisconnected (triggered when a connection is disconned)For all events to be dispatched there are 4 event dispatchers. The following is a list of the dispatchters and their in-/outgoning events:

DispatcherIncomming eventsOutgoing eventsPurposeHandshakeEventSubscriberHandshakeEventConnectEventHandle handshake and dispatch a connect event when successfullConnectionEventSubscriberConnectEvent, DisconnectEventDataEvent, DisconnectEventHandle connection and map connection eventsDataEventSubscriberDataEventFrameEventParse incomming data to a frame and dispatch as frame eventFrameEventSubscriberFrameEventMessageEventHandle incomming frame event and dispatch a Message event if the opcode is TEXT### Running the example

[](#running-the-example)

There is a simple chat application included in this project. To run this, use the following commands:

```
php example/socket.php
php -S 127.0.0.1:8080 -t ./example/web
```

**You must run both commands separate from each other**

### Known issues

[](#known-issues)

1. Fragmentations is not supported yet
2. Encode function of the encoder does not yet support masking
3. Strings longer than 65536 cannot be received due to buffering

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~5 days

Total

2

Last Release

2469d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/553da121f7aee7ae5346e8a9cd13a6812a063eb0f0faba35f59f6f17e49bec16?d=identicon)[nusje2000](/maintainers/nusje2000)

---

Top Contributors

[![nusje2000](https://avatars.githubusercontent.com/u/17175959?v=4)](https://github.com/nusje2000 "nusje2000 (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nusje2000-websockets/health.svg)

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

###  Alternatives

[symfony/mailer

Helps sending emails

1.6k368.1M949](/packages/symfony-mailer)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M646](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[phpro/soap-client

A general purpose SoapClient library

8885.6M45](/packages/phpro-soap-client)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)

PHPackages © 2026

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