PHPackages                             micilini/php-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. [HTTP &amp; Networking](/categories/http)
4. /
5. micilini/php-websockets

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

micilini/php-websockets
=======================

Native PHP WebSocket and realtime chat library built from scratch. Works standalone or with Laravel.

v1.0.2(1mo ago)041MITPHPPHP ^8.2

Since May 10Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependencies (6)Versions (6)Used By (0)

PHPSockets
==========

[](#phpsockets)

Native PHP WebSocket and realtime chat foundation built from scratch with PHP sockets. Works standalone with plain PHP or inside Laravel applications.

 [![PHP 8.2+](https://camo.githubusercontent.com/dff57f35e05ba5bb847a182b0de56ce00f5b33eb4bfb86b371e2c69de0accee0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/) [![Laravel 10/11/12/13](https://camo.githubusercontent.com/27a68c08c5b5a050b49820229b16f570e4c57c250d8aac0ab2c4de438a0c4152/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532463131253246313225324631332d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com/) [![MIT License](https://camo.githubusercontent.com/153acf9dff19deb8abfc598c53bac50a4ceae0f5c83a552711060d3d78d2c057/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e3f7374796c653d666f722d7468652d6261646765)](https://github.com/micilini/php-websockets/blob/master/LICENSE.txt) [![Tests](https://camo.githubusercontent.com/b847854bce9bbfbb3d21e6f015d6638d7eca1e790aca39b4cd8f484e75b37b51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6963696c696e692f7068702d776562736f636b6574732f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666f722d7468652d6261646765266c6162656c3d5465737473)](https://github.com/micilini/php-websockets/actions) [![Packagist](https://camo.githubusercontent.com/1e6e73de68369ee7475b21f44d1c56f38643175888c8a6b2b751fb70448fa2f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6963696c696e692f7068702d776562736f636b6574733f7374796c653d666f722d7468652d6261646765266c6162656c3d5061636b6167697374)](https://packagist.org/packages/micilini/php-websockets)

 **Pure PHP WebSockets. Realtime chat. Private rooms. Bots. Laravel-ready.**

---

Application Images
------------------

[](#application-images)

 [![Image 1](./images/screen-1.png)](./images/screen-1.png)

 [![Image 2](./images/screen-2.png)](./images/screen-2.png)

 [![Image 3](./images/screen-3.png)](./images/screen-3.png)

 [![Image 4](./images/screen-4.png)](./images/screen-4.png)

---

Overview
--------

[](#overview)

**PHPSockets** started in 2016 as an educational experiment demonstrating how to build a WebSocket server directly with PHP sockets, without Node.js, without socket.io, and without a third-party realtime runtime.

The project has now been rebuilt as a modern Composer package for PHP 8.2+, with a clean architecture, WebSocket protocol primitives, a realtime server runtime, a chat kit, private conversations, private group rooms, small attachments, emoji-safe payloads, bot hooks, optional storage adapters, and Laravel integration.

The goal is not only to provide a chat example.

The goal is to provide a **native PHP realtime foundation** that developers can use to build:

- realtime chat widgets;
- support chat systems;
- private rooms;
- collaborative dashboards;
- notification servers;
- internal realtime tools;
- chatbot-ready messaging flows;
- Laravel-powered realtime applications.

---

Features
--------

[](#features)

- **Native WebSocket core** — handshake, frames, opcodes, close codes, ping/pong and payload validation.
- **Pure PHP socket runtime** — no socket.io, Ratchet, ReactPHP, Swoole, Workerman or Node.js required.
- **Realtime server layer** — connection registry, lifecycle events, message dispatching and safe closing.
- **Chat Kit** — sessions, unique display names, presence, global messages, direct messages and rooms.
- **EasyChat example** — simple global chat for beginners.
- **MediumChat example** — callback/event-driven chat for customization.
- **PrivateChat example** — global room, direct 1:1 conversations, private group rooms and unread badges.
- **Private group rooms** — create a room with selected online users only.
- **Typing indicators** — user feedback for active conversations.
- **Message receipts** — simple sent/received/read states in examples.
- **Emoji support** — safe UTF-8 text payloads with a built-in emoji picker in examples.
- **Small attachments** — images, PDFs and text files up to the configured limit.
- **Downloadable file messages** — delivered attachments include a download action.
- **Fragmented text frame support** — large JSON text messages can be reassembled safely.
- **Storage adapters** — in-memory, file JSONL messages and PDO-based SQL storage.
- **Database migrations** — SQLite, MySQL and PostgreSQL schemas through the migration runner.
- **Bot hooks** — register lightweight bots that can respond in global, direct and private group contexts.
- **Laravel integration** — Service Provider, Facade, publishable config and Artisan commands.
- **Quality tooling** — PHPUnit, PHPStan, PHP CS Fixer and GitHub Actions.
- **Legacy preserved** — the original 2016 EasyChat and MediumChat implementations are kept for historical reference.

---

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

[](#installation)

Install through Composer:

```
composer require micilini/php-websockets
```

For local development:

```
git clone https://github.com/micilini/php-websockets.git
cd php-websockets
composer install
```

---

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

[](#requirements)

Required:

- PHP 8.2 or higher;
- `ext-sockets`;
- `ext-json`;
- Composer.

Optional:

- `ext-pdo` for SQL storage adapters;
- `ext-pdo_sqlite` for SQLite storage and tests;
- Laravel 10, 11, 12 or 13 for Laravel integration.

---

Quick Start
-----------

[](#quick-start)

### Standalone PHP server

[](#standalone-php-server)

Create a simple WebSocket chat server:

```
