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

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

danielealbano/php-websocket-s2c
===============================

0.3.1(9y ago)5601Apache-2.0PHP

Since Aug 16Pushed 9y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

php-websocket-s2c
=================

[](#php-websocket-s2c)

Introduction
------------

[](#introduction)

php-websocket-s2c is a PHP Websocket native implementation able to serve requests through apache, nginx or any other webserver and proxy without any particular configuration.

The websocket support in PHP is almost absent because, usually, you need support for them at webserver/proxy level, the approach used in this implementation allows to send packets only from the server to the client and not the reverse without having to change any configuration parameter on your proxy and/or on your webserver, the **s2c** suffixs stands for **Server To Client**.

Supported features
------------------

[](#supported-features)

The library supports the following features:

- Server to Client messages (text (json), binary, ping/pong)
- Fragmented messages (used to stream data)
- Packet size up to 2^64
- Try to automatically disable http compression (gzip) and chunking
- Websocket Protocols (Sec-Websocket-Protocol header)
- Protocol version 13 ([https://en.wikipedia.org/wiki/WebSocket#Browser\_implementation](https://en.wikipedia.org/wiki/WebSocket#Browser_implementation))

What is unsupported and/or untested:

- Extensions (multiplexing, compression, etc.)
- SSL/TLS

This library has been tested with PHP 5.4, PHP 5.5 and PHP 5.6 on Apache 2.2 with mod\_php

Bugs
----

[](#bugs)

This library is very young and uses tricks to avoid starting a standalone webserver, if something doesn't work, before opening an issue, please check if your webserver is using/requesting:

- the compression enabled (Content-Encoding header should be absent or its value should be **identity**);
- the chunking enabled (Transfer-Encoding header should be absent or its value should be **identity**).

When you report an issue please remember to mention:

- if Content-Length header has a value different than zero;
- if Connection header is absent or has a different value than **Upgrade**;
- if Upgrade header is absent or has a different value than **websocket**;
- Your webserver (name and version);
- If you are using php as module or as fastcgi;
- If you are using a proxy and, if yes, which one

Examples
--------

[](#examples)

### Plain Websocket

[](#plain-websocket)

##### New the websocket server

[](#new-the-websocket-server)

```
require_once('src/WebSocket.php');
require_once('src/Frame.php');

$ws = new WebsocketS2C\WebSocket();
```

Using composer will not be necessary to include the sources.

##### Check if a websocket is requested

[](#check-if-a-websocket-is-requested)

```
if ($ws->isWebsocket() == false) {
	echo 'Not a websocket!';
	die();
}
```

##### Accept connections

[](#accept-connections)

```
$ws->accept();
```

##### Send text frames (first example)

[](#send-text-frames-first-example)

```
$ws->text(utf8_encode('This is a test!'));
```

##### Send text frames (second example)

[](#send-text-frames-second-example)

```
for($i = 0; $i < 3; $i++) {
	$ws->text(utf8_encode('Loop ' . $i));
	sleep(1);
}
```

##### Send json frames

[](#send-json-frames)

```
$ws->json([
	'hello' => 'world'
]);
```

##### Send binary (blob) frames

[](#send-binary-blob-frames)

```
$ws->binary('This is a test!');
```

##### Stream data

[](#stream-data)

```
$isFirst = true;
$ws->text('[', false, false);
foreach([ 'this', 'is', 'a', 'multipart', 'message' ] as $part) {
	if ($isFirst == false) {
		$ws->text(',', false, false);
	}

	$ws->json([
		'alot' => true,
		'of' => true,
		'data' => $part
	], false);

	$isFirst = false;
}
$ws->text(']');
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

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

3555d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a711b3de1da5425b147455408693b0d05588e37446ce44c51bc4c16ae2cfd45?d=identicon)[dalbano](/maintainers/dalbano)

---

Top Contributors

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

---

Tags

phpjsonserverwebsocketnginxapachelighttpd

### Embed Badge

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

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

###  Alternatives

[datto/json-rpc-http

HTTP client and server for JSON-RPC 2.0

66525.9k5](/packages/datto-json-rpc-http)[hemiframe/php-websocket

PHP WebSocket server and client library

4911.0k](/packages/hemiframe-php-websocket)[warriorxk/phpwebsockets

A websocket library with support for IPC using socket pairs

1225.3k](/packages/warriorxk-phpwebsockets)[swoole-bundle/swoole-bundle

Open/Swoole Symfony Bundle

6650.4k](/packages/swoole-bundle-swoole-bundle)[morozovsk/websocket-examples

examples for simple php websocket server: simple chat (single daemon) - http://sharoid.ru/chat.html , pro chat (master + worker) - http://sharoid.ru/chat2.html , simple game - http://sharoid.ru/game.html

382.3k](/packages/morozovsk-websocket-examples)

PHPackages © 2026

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