PHPackages                             phrity/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. phrity/websocket

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

phrity/websocket
================

WebSocket client and server

3.6.2(4mo ago)2184.1M—3.5%23[1 issues](https://github.com/sirn-se/websocket-php/issues)20ISCPHPPHP ^8.1CI passing

Since Nov 22Pushed 4mo ago5 watchersCompare

[ Source](https://github.com/sirn-se/websocket-php)[ Packagist](https://packagist.org/packages/phrity/websocket)[ Docs](https://phrity.sirn.se/websocket)[ RSS](/packages/phrity-websocket/feed)WikiDiscussions v3.6-main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (67)Used By (20)

[![Phrity Websocket](docs/logotype.png)](docs/logotype.png)

Websocket Client and Server for PHP
===================================

[](#websocket-client-and-server-for-php)

[![Build Status](https://github.com/sirn-se/websocket-php/actions/workflows/acceptance.yml/badge.svg)](https://github.com/sirn-se/websocket-php/actions)

This library contains WebSocket client and server for PHP.

The client and server provides methods for reading and writing to WebSocket streams.

This repo replaces the abandoned `textalk/websocket` repo and is maintained by Sören Jensen, who has been maintaining the original since `v1.3`.

Some features
-------------

[](#some-features)

- Client and multi-connection Server
- `ws` (TCP) and `wss` (SSL) support
- Listener callbacks on incoming messages and other events
- Close and Ping/Pong handling (standard middlewares)
- Deflate compression (middleware)
- Additional optional middlewares and ability to create own middlewares
- Support message fragmentation and payload masking

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

[](#documentation)

- [Documentation](docs/Index.md)
- [Client](docs/Client.md) - The WebSocket client
- [Server](docs/Server.md) - The WebSocket server
- [Changelog](docs/Changelog.md) - The changelog of this repo
- [Contributing](docs/Contributing.md) - Contributors and requirements
- [Examples](docs/Examples.md) - Examples

Migration
---------

[](#migration)

- [v1 -&gt; v2](docs/Migrate_1_2.md) - How to migrate from v1 to v2
- [v2 -&gt; v3](docs/Migrate_2_3.md) - How to migrate from v2 to v3

Installing
----------

[](#installing)

Preferred way to install is with [Composer](https://getcomposer.org/).

```
composer require phrity/websocket

```

Client
------

[](#client)

The [client](docs/Client.md) can read and write on a WebSocket stream. It internally supports Upgrade handshake and implicit close and ping/pong operations.

Set up a WebSocket Client for request/response strategy.

```
$client = new WebSocket\Client("wss://echo.websocket.org/");
$client
    // Add standard middlewares
    ->addMiddleware(new WebSocket\Middleware\CloseHandler())
    ->addMiddleware(new WebSocket\Middleware\PingResponder())
    ;

// Send a message
$client->text("Hello WebSocket.org!");

// Read response (this is blocking)
$message = $client->receive();
echo "Got message: {$message->getContent()} \n";

// Close connection
$client->close();
```

Set up a WebSocket Client for continuous subscription

```
$client = new WebSocket\Client("wss://echo.websocket.org/");
$client
    // Add standard middlewares
    ->addMiddleware(new WebSocket\Middleware\CloseHandler())
    ->addMiddleware(new WebSocket\Middleware\PingResponder())
    // Listen to incoming Text messages
    ->onText(function (WebSocket\Client $client, WebSocket\Connection $connection, WebSocket\Message\Message $message) {
        // Act on incoming message
        echo "Got message: {$message->getContent()} \n";
        // Possibly respond to server
        $client->text("I got your your message");
    })
    ->start();
```

Server
------

[](#server)

The [server](docs/Server.md) is a multi connection, listening server. It internally supports Upgrade handshake and implicit close and ping/pong operations.

Set up a WebSocket Server for continuous listening

```
$server = new WebSocket\Server();
$server
    // Add standard middlewares
    ->addMiddleware(new WebSocket\Middleware\CloseHandler())
    ->addMiddleware(new WebSocket\Middleware\PingResponder())
    // Listen to incoming Text messages
    ->onText(function (WebSocket\Server $server, WebSocket\Connection $connection, WebSocket\Message\Message $message) {
        // Act on incoming message
        echo "Got message: {$message->getContent()} \n";
        // Possibly respond to client
        $connection->text("I got your your message");
    })
    ->start();
```

### License

[](#license)

[ISC License](LICENSE.md)

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance75

Regular maintenance activity

Popularity62

Solid adoption and visibility

Community39

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 86.3% 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 ~19 days

Recently: every ~64 days

Total

59

Last Release

148d ago

Major Versions

0.1.0 → 1.6.42022-11-22

1.7.0 → 2.0.02023-10-28

1.7.2 → 2.1.02023-12-17

1.7.3 → 3.0.02024-06-15

PHP version history (6 changes)1.6.3PHP ^7.4 | ^8.0

1.5.8PHP ^7.2 | ^8.0

1.4.3PHP ^7.1

1.3.1PHP ^5.4|^7.0

2.0.0PHP ^8.0

2.2.1PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4255391?v=4)[Sören Jensen](/maintainers/sirn-se)[@sirn-se](https://github.com/sirn-se)

---

Top Contributors

[![sirn-se](https://avatars.githubusercontent.com/u/4255391?v=4)](https://github.com/sirn-se "sirn-se (410 commits)")[![pmccarren](https://avatars.githubusercontent.com/u/4959702?v=4)](https://github.com/pmccarren "pmccarren (14 commits)")[![fiddur](https://avatars.githubusercontent.com/u/148166?v=4)](https://github.com/fiddur "fiddur (11 commits)")[![Sebastix](https://avatars.githubusercontent.com/u/582669?v=4)](https://github.com/Sebastix "Sebastix (5 commits)")[![slezakattack](https://avatars.githubusercontent.com/u/1261638?v=4)](https://github.com/slezakattack "slezakattack (3 commits)")[![pieterocp](https://avatars.githubusercontent.com/u/68863060?v=4)](https://github.com/pieterocp "pieterocp (3 commits)")[![zapling](https://avatars.githubusercontent.com/u/15123086?v=4)](https://github.com/zapling "zapling (2 commits)")[![marcroberts](https://avatars.githubusercontent.com/u/43874?v=4)](https://github.com/marcroberts "marcroberts (2 commits)")[![UksusoFF](https://avatars.githubusercontent.com/u/1931442?v=4)](https://github.com/UksusoFF "UksusoFF (2 commits)")[![Logioniz](https://avatars.githubusercontent.com/u/1052312?v=4)](https://github.com/Logioniz "Logioniz (2 commits)")[![rmeisler-applovin](https://avatars.githubusercontent.com/u/99207377?v=4)](https://github.com/rmeisler-applovin "rmeisler-applovin (2 commits)")[![rmeisler](https://avatars.githubusercontent.com/u/1885391?v=4)](https://github.com/rmeisler "rmeisler (1 commits)")[![RobQuistNL](https://avatars.githubusercontent.com/u/1442796?v=4)](https://github.com/RobQuistNL "RobQuistNL (1 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (1 commits)")[![sloonz](https://avatars.githubusercontent.com/u/142145?v=4)](https://github.com/sloonz "sloonz (1 commits)")[![swmcdonnell](https://avatars.githubusercontent.com/u/6199058?v=4)](https://github.com/swmcdonnell "swmcdonnell (1 commits)")[![vkuptcov](https://avatars.githubusercontent.com/u/1507196?v=4)](https://github.com/vkuptcov "vkuptcov (1 commits)")[![waldyrious](https://avatars.githubusercontent.com/u/478237?v=4)](https://github.com/waldyrious "waldyrious (1 commits)")[![webpatser](https://avatars.githubusercontent.com/u/25720?v=4)](https://github.com/webpatser "webpatser (1 commits)")[![RaoH](https://avatars.githubusercontent.com/u/738935?v=4)](https://github.com/RaoH "RaoH (1 commits)")

---

Tags

phpphp-librarywebsocketwebsocket-clientwebsocket-serverclientserverwebsocket

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[swow/swow

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

1.3k2.1M84](/packages/swow-swow)[cboden/ratchet

PHP WebSocket library

6.4k21.4M239](/packages/cboden-ratchet)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[amphp/http-server

A non-blocking HTTP application server for PHP based on Amp.

1.3k4.5M81](/packages/amphp-http-server)[ratchet/pawl

Asynchronous WebSocket client

6148.9M214](/packages/ratchet-pawl)[amphp/websocket-client

Async WebSocket client for PHP based on Amp.

1623.0M39](/packages/amphp-websocket-client)

PHPackages © 2026

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