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 today

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

Maintenance31

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://avatars.githubusercontent.com/u/52377199?v=4)[kosar ahmadi](/maintainers/kosar501)[@kosar501](https://github.com/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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M90](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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