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

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

dimogrudev/php-websocket
========================

No-dependency implementation of WebSocket server in PHP

v1.0.0(10mo ago)010MITPHPPHP ^8.4

Since Jul 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/dimogrudev/php-websocket)[ Packagist](https://packagist.org/packages/dimogrudev/php-websocket)[ RSS](/packages/dimogrudev-php-websocket/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP WebSocket Server
====================

[](#php-websocket-server)

A zero-dependency native implementation of WebSocket server in PHP, made according to [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455).

Lightweight and minimalistic.

Features
--------

[](#features)

- SSL/TLS encryption.
- Binary and textual data frames, both sending and receiving.
- Control frames (ping/pong/close).
- Built-in non-blocking timers.

Requirements
------------

[](#requirements)

- PHP 8.4+

Important

If you plan to run websockets on a shared hosting, remember that most shared hosting providers block ports for any third-party usage. You will likely have to use a VPS or a dedicated server.

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

[](#installation)

This library may be installed via [Composer](https://getcomposer.org/):

```
composer require dimogrudev/php-websocket
```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

// Create an instance of the server class
// 0.0.0.0 is set as host to make the server reachable at all IPv4 addresses
$server = new WebSocket\Server('0.0.0.0', 8443);
// Enable encryption and provide certificate files
$server->encryption(true, '../example_le1.crt', '../example_le1.key');

// Print the number of users online every 30 seconds
$server->setTimer(function () use ($server): void {
    print "Current online: {$server->online} user(s)\n";
}, 30000, true);
// Handle incoming messages
$server->onMessageReceive(function ($client, $message): void {
    if ($message->binary) {
        print "{$client->ipAddr} (#{$client->id}) sends binary message ({$message->length} bytes)\n";
    } else {
        print "{$client->ipAddr} (#{$client->id}) sends `{$message->payload}`\n";
    }
});

$server->start();
```

Note

Due to their security policies, web browsers won't allow to open a non-secure WebSocket connection (ws:) on a secure website (https:). Using an SSL/TLS certificate (e.g. **Let's Encrypt**, not a self-signed one) is mandatory in this case.

### Timers

[](#timers)

```
// Create a timer to run function repeatedly with a 500 milliseconds interval
// It provides timer ID which may be used for later cancellation
$timerId = $server->setTimer(function (): void {}, 500, true);
// Cancel the timer
$server->clearTimer($timerId);
```

### Callbacks

[](#callbacks)

```
// Server starts
$server->onServerStart(function (): void {});
// Server stops
$server->onServerStop(function(): void {});
// Client establishes connection and sends handshake request
// Return TRUE to accept the request or FALSE to reject it and disconnect the client
$server->onClientConnect(function ($client, $request): bool {});
// Client disconnects
$server->onClientDisconnect(function ($client): void {});
// Client sends message
$server->onMessageReceive(function ($client, $message): void {});
```

License
-------

[](#license)

The MIT License (MIT). For more information, please see [LICENSE](/LICENSE).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance68

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

303d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/385921417b0621b693ff4fe0ad6ce11869af03e860f929697953b7a67f3e3a8a?d=identicon)[dimogrudev](/maintainers/dimogrudev)

---

Top Contributors

[![dimogrudev](https://avatars.githubusercontent.com/u/95988098?v=4)](https://github.com/dimogrudev "dimogrudev (3 commits)")

---

Tags

event-looplibrarylightweightminimalphpphp8rfc-6455serverwebsocketserverwebsocketrfc6455

### Embed Badge

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

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

###  Alternatives

[cboden/ratchet

PHP WebSocket library

6.4k21.4M239](/packages/cboden-ratchet)[hhxsv5/laravel-s

🚀 LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

3.9k676.0k10](/packages/hhxsv5-laravel-s)[swow/swow

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

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

RFC6455 WebSocket protocol handler

23433.7M69](/packages/ratchet-rfc6455)[phrity/websocket

WebSocket client and server

2184.1M27](/packages/phrity-websocket)[amphp/websocket-server

Websocket server for Amp's HTTP server.

124265.1k20](/packages/amphp-websocket-server)

PHPackages © 2026

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