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

ActiveProject

gevman/s2c-websocket
====================

One way (server2client) simple WebSocket PHP library

1.0.1(9y ago)729MITPHPPHP &gt;=5.4

Since Dec 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gevorgmansuryan/s2c-websocket)[ Packagist](https://packagist.org/packages/gevman/s2c-websocket)[ RSS](/packages/gevman-s2c-websocket/feed)WikiDiscussions master Synced 2mo ago

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

PhpSocket
=========

[](#phpsocket)

One way (server2client) simple WebSocket PHP library

Installation (using composer)
-----------------------------

[](#installation-using-composer)

```
composer require gevman/s2c-websocket
```

### Listener methods

[](#listener-methods)

##### Constructor(string $host, int $port, string $path, string $identityParam, bool $ssl)

[](#constructorstring-host-int-port-string-path-string-identityparam-bool-ssl)

###### Create Listener

[](#create-listener)

- `$host` - server ip or domain
- `$port` - port for server socket
- `$path` - default path for socket connection
- `$identityParam` - parameter to resolve identity
- `$ssl` - if true will be used `wss` protocol, otherwise `ws` protocol

##### void listen()

[](#void-listen)

###### Start listening

[](#start-listening)

##### void onUpdate(function(array $AllIdentities) {/\* \*/})

[](#void-onupdatefunctionarray-allidentities--)

###### Triggers when user connected or disconnected

[](#triggers-when-user-connected-or-disconnected)

- `$AllIdentities` - List of all identities along with params

##### void onClientConnect(function(array $identity) {/\* \*/})

[](#void-onclientconnectfunctionarray-identity--)

###### Triggers when user connected

[](#triggers-when-user-connected)

- `$identity` - Array of identity params of connected user

##### void onClientDisconnect(function(array $identity) {/\* \*/})

[](#void-onclientdisconnectfunctionarray-identity--)

###### Triggers when user disconnected

[](#triggers-when-user-disconnected)

- `$identity` - Array of identity params of disconnected user

##### void onMessage(function(array $identities, string $message) {/\* \*/})

[](#void-onmessagefunctionarray-identities-string-message--)

###### Triggers when server sends message

[](#triggers-when-server-sends-message)

- `$identities` - List of identities which will receive message
- `$message` - message content

##### void onError(function(Exception $e) {/\* \*/})

[](#void-onerrorfunctionexception-e--)

###### Triggers on error

[](#triggers-on-error)

- `$host` - Exception object of error

##### Example

[](#example)

###### Client side (JavaScript)

[](#client-side-javascript)

```
var webSocket = new WebSocket('ws://example.com:8080/socket/test/id/1/username/test/some-param/some-value');
```

###### Server side (PHP)

[](#server-side-php)

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

$listener = new \Gevman\PhpSocket\Listener('example.com', 8080, '/socket/test', 'id', false);

$listener->events->onError(function(Exception $e) {
    printf('error: %s in %s at line %s', $e->getMessage(), $e->getFile(), $e->getLine());
});

$listener->events->onClientConnect(function($identity) {
    printf("Client connected: %s\n\n", $identity['id']);
});

$listener->events->onClientDisconnect(function($identity) {
    printf("Client disconnected: %s\n\n", $identity['id']);
});

$listener->events->onMessage(function($identities, $message) {
    printf("new message: %s to %s\n\n", $message, implode(',', array_column($identities, 'id')));
});

$listener->events->onUpdate(function($AllIdentities) {
    file_put_contents('online-users.txt', array_column($AllIdentities, 'id'));
});

$listener->listen();
```

### Notifier methods

[](#notifier-methods)

##### Constructor(string $host, int $port)

[](#constructorstring-host-int-port)

###### Create Notifier

[](#create-notifier)

- `$host` - server ip or domain
- `$port` - port of server socket

##### bool notify(mixed $message, mixed $to)

[](#bool-notifymixed-message-mixed-to)

###### Send message to server which will be delivered to listed identities

[](#send-message-to-server-which-will-be-delivered-to-listed-identities)

- `$message` - Message to send
- `$to` - Identity or list identities to be notified, if empty will be notified all identities

##### Example

[](#example-1)

###### Server side (PHP)

[](#server-side-php-1)

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

$notifier = new \Gevman\PhpSocket\Notifier('example.com', 8080);
$notifier->notify(['something' => 'happened', 'new' => 'message'], 1);
```

###### Client side (JavaScript)

[](#client-side-javascript-1)

```
var webSocket = new WebSocket('ws://example.com:8080/socket/test/id/1/username/test/some-param/some-value');
webSocket.onmessage(function (message) {
    var data = JSON.parse(message.data);
    console.log(data.something);
    console.log(data.new);
});
```

---

For https sites You need use `wss` connection, For this You need pass `true` for last parameter of Listener constructor and use Apache ProxyPass in Your apache config

```
ProxyPass /wss ws://example.com:8080

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Every ~0 days

Total

2

Last Release

3426d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/efb5a7bc511eaa76c7896073be5577485fed06c0408bc01207e021540cd4b403?d=identicon)[gevorgmansuryan](/maintainers/gevorgmansuryan)

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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