PHPackages                             kosar501/phpwebsocket - 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. kosar501/phpwebsocket

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

kosar501/phpwebsocket
=====================

a simple package interaction websocket server and client

01PHP

Since Jan 13Pushed 1y ago1 watchersCompare

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

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

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

[](#websocket-server-php-package)

Overview
--------

[](#overview)

Real-time messaging platform utilizing WebSocket for bidirectional communication between clients and a ZeroMQ-powered backend for scalable, asynchronous message distribution. This project enables efficient and low-latency communication across multiple connected clients, with ZeroMQ handling high-throughput messaging and WebSocket ensuring real-time updates in a responsive web interface.

**WebSocket Server**: Listens for WebSocket connections and broadcasts messages to connected clients.

---

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

[](#installation)

### Step 1: Clone the Repository

[](#step-1-clone-the-repository)

Clone the repository to your local machine:

```
git clone https://github.com/kosar501/PhpWebSocket.git
cd your-project-folder
```

### Step 2: Install Dependencies

[](#step-2-install-dependencies)

```
composer install
```

### Step 2: Install Dependencies

[](#step-2-install-dependencies-1)

```
composer install
```

Running the Server
------------------

[](#running-the-server)

There are two main components in the system: the WebSocket server and the Redis queue consumer. You can run both components as separate processes, and they will be managed using Supervisor.

### 1: Running WebSocket Server Along With ZMQ

[](#1-running-websocket-server-along-with-zmq)

#### 1.1: Manually (for development or testing)

[](#11-manually-for-development-or-testing)

```
php server.php
```

#### 1.2: Using Supervisor (Recommended for production)

[](#12-using-supervisor-recommended-for-production)

```
[program:websocket-server]
command=php /path/to/your/project/server.php
autostart=true
autorestart=true
stderr_logfile=/var/log/websocket_server.err.log
stdout_logfile=/var/log/websocket_server.out.log
```

After adding this configuration, update Supervisor:

```
supervisorctl start websocket-server
```

Start the WebSocket server:

```
supervisorctl start websocket-server
```

If you encounter issues, restart the processes via Supervisor:

```
supervisorctl restart websocket-server
```

How to Use
----------

[](#how-to-use)

You can use the Client class to send messages to the WebSocket server through Redis. This class sends messages to the Redis queue that the consumer will process.

### Server Side:

[](#server-side)

#### Example:

[](#example)

```
    $client = new MessagePublisher();

    // Prepare the message as an associative array
    $message = json_encode(['topic' => 'news', 'content' => 'This is a test message']);
    $client->sendMessage($message);
```

### On the Client Side (Web Browser):

[](#on-the-client-side-web-browser)

#### Example:

[](#example-1)

You can check examples folder

```
const socket = new WebSocket('ws://127.0.0.1:5555');

socket.onmessage = function(event) {
    const message = JSON.parse(event.data);
    console.log('Received message:', message);
    // Now you can access the message properties like message.action, message.username, etc.
};
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0398303c3c848eb70e23d07ccd3699ed668804894535a10fe8a265a4b3673096?d=identicon)[kosar501](/maintainers/kosar501)

---

Top Contributors

[![kosar501](https://avatars.githubusercontent.com/u/52377199?v=4)](https://github.com/kosar501 "kosar501 (9 commits)")

### Embed Badge

![Health badge](/badges/kosar501-phpwebsocket/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

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

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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