PHPackages                             tmsolution/phpws - 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. tmsolution/phpws

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

tmsolution/phpws
================

WebSocket Server and Client library for PHP

1.2(8y ago)0131PHP

Since Nov 21Pushed 8y ago2 watchersCompare

[ Source](https://github.com/TMSolution/phpws)[ Packagist](https://packagist.org/packages/tmsolution/phpws)[ RSS](/packages/tmsolution-phpws/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (3)Versions (7)Used By (1)

WebSocket Server and Client library for PHP. Works with the latest HyBi specifications, as well the older Hixie #76 specification used by older Chrome versions and some Flash fallback solutions.

This project was started to bring more interactive features to

Features
========

[](#features)

Server

- Hixie #76 and Hybi #12 protocol versions
- Flash client support (also serves XML policy file on the same port)
    - See  for a compatible Flash Client
- Native Firefox, Safari (iPod / iPhone as well), Chrome and IE10 support. With Flash Client every browser supporting Flash works as well (including IE6-9, Opera, Android and other older desktop browsers).
- Opera (Mobile) supports WebSockets natively but support has been disabled by default. Can be enabled in opera:config.

Client

- Hybi / Hixie76 support.
- Event-based Async I/O

Getting started
===============

[](#getting-started)

The easiest way to set up PHPWS is by using it as Composer dependency. Add the following to your composer.json

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/Devristo/phpws"
        }
    ],
    "require": {
        "devristo/phpws": "dev-master"
    }
}
```

And run `php composer.phar install`

To verify it is working create a time.php in your project root

```
require_once("vendor/autoload.php");
use Devristo\Phpws\Server\WebSocketServer;

$loop = \React\EventLoop\Factory::create();

// Create a logger which writes everything to the STDOUT
$logger = new \Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream("php://output");
$logger->addWriter($writer);

// Create a WebSocket server using SSL
$server = new WebSocketServer("tcp://0.0.0.0:12345", $loop, $logger);

$loop->addPeriodicTimer(0.5, function() use($server, $logger){
    $time = new DateTime();
    $string = $time->format("Y-m-d H:i:s");
    $logger->notice("Broadcasting time to all clients: $string");
    foreach($server->getConnections() as $client)
        $client->sendString($string);
});

// Bind the server
$server->bind();

// Start the event loop
$loop->run();
```

And a client time.html as follows

```

        WebSocket TEST

        Server Time

            var socket = new WebSocket("ws://localhost:12345/");
            socket.onmessage = function(msg) {
                document.getElementById("time").innerText = msg.data;
            };

```

Now run the time.php from the command line and open time.html in your browser. You should see the current time, broadcasted by phpws at regular intervals. If this works you might be interested in more complicated servers in the examples folder.

Getting started with the Phpws Client
=====================================

[](#getting-started-with-the-phpws-client)

The following is a client for the websocket server hosted at

```
require_once("vendor/autoload.php");                // Composer autoloader

$loop = \React\EventLoop\Factory::create();

$logger = new \Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream("php://output");
$logger->addWriter($writer);

$client = new \Devristo\Phpws\Client\WebSocket("ws://echo.websocket.org/?encoding=text", $loop, $logger);

$client->on("request", function($headers) use ($logger){
    $logger->notice("Request object created!");
});

$client->on("handshake", function() use ($logger) {
    $logger->notice("Handshake received!");
});

$client->on("connect", function($headers) use ($logger, $client){
    $logger->notice("Connected!");
    $client->send("Hello world!");
});

$client->on("message", function($message) use ($client, $logger){
    $logger->notice("Got message: ".$message->getData());
    $client->close();
});

$client->open();
$loop->run();
```

Known Issues
============

[](#known-issues)

- Lacks ORIGIN checking (can be implemented manually in onConnect using getHeaders(), just disconnect the user when you dont like the Origin header)
- No support for extension data from the HyBi specs.

Requirements
============

[](#requirements)

*Server*

- PHP 5.4
- Open port for the server
- PHP OpenSSL module to run a server over a encrypted connection
- [http://pecl.php.net/package/pecl\_http](http://pecl.php.net/package/pecl_http) as its a dependency of Zend\\Uri
- Composer dependencies \* These will be installed automatically when using phpws as a composer package.
- Reactphp
- ZF2 Logger

*Client*

- PHP 5.4
- Server that implements the HyBi (#8-#12) draft version
- PHP OpenSSL module to connect using SSL (wss:// uris)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 84% 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

3021d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f92fd8e073eee2f6de77b291d4f3a93bb691353a2dbe4f2e682bcbbb07929e6?d=identicon)[JacekLozinski](/maintainers/JacekLozinski)

---

Top Contributors

[![Devristo](https://avatars.githubusercontent.com/u/1564257?v=4)](https://github.com/Devristo "Devristo (152 commits)")[![JacekLozinski](https://avatars.githubusercontent.com/u/18549958?v=4)](https://github.com/JacekLozinski "JacekLozinski (6 commits)")[![DannyWilkerson](https://avatars.githubusercontent.com/u/6262325?v=4)](https://github.com/DannyWilkerson "DannyWilkerson (4 commits)")[![sammarks](https://avatars.githubusercontent.com/u/424093?v=4)](https://github.com/sammarks "sammarks (2 commits)")[![perfect-solutions](https://avatars.githubusercontent.com/u/9501098?v=4)](https://github.com/perfect-solutions "perfect-solutions (2 commits)")[![donjuanica](https://avatars.githubusercontent.com/u/1425309?v=4)](https://github.com/donjuanica "donjuanica (1 commits)")[![fatganz](https://avatars.githubusercontent.com/u/304809?v=4)](https://github.com/fatganz "fatganz (1 commits)")[![felixgilles](https://avatars.githubusercontent.com/u/900854?v=4)](https://github.com/felixgilles "felixgilles (1 commits)")[![linniksa](https://avatars.githubusercontent.com/u/424343?v=4)](https://github.com/linniksa "linniksa (1 commits)")[![rmccue](https://avatars.githubusercontent.com/u/21655?v=4)](https://github.com/rmccue "rmccue (1 commits)")[![romanmatena](https://avatars.githubusercontent.com/u/164995?v=4)](https://github.com/romanmatena "romanmatena (1 commits)")[![sagebind](https://avatars.githubusercontent.com/u/2192863?v=4)](https://github.com/sagebind "sagebind (1 commits)")[![sfranzyshen](https://avatars.githubusercontent.com/u/5503445?v=4)](https://github.com/sfranzyshen "sfranzyshen (1 commits)")[![stgnet](https://avatars.githubusercontent.com/u/1020203?v=4)](https://github.com/stgnet "stgnet (1 commits)")[![alexmace](https://avatars.githubusercontent.com/u/207391?v=4)](https://github.com/alexmace "alexmace (1 commits)")[![yura999999999](https://avatars.githubusercontent.com/u/24545299?v=4)](https://github.com/yura999999999 "yura999999999 (1 commits)")[![arronwoods](https://avatars.githubusercontent.com/u/778702?v=4)](https://github.com/arronwoods "arronwoods (1 commits)")[![bramus](https://avatars.githubusercontent.com/u/213073?v=4)](https://github.com/bramus "bramus (1 commits)")[![ckwalsh](https://avatars.githubusercontent.com/u/68822?v=4)](https://github.com/ckwalsh "ckwalsh (1 commits)")[![dlarin88](https://avatars.githubusercontent.com/u/30315996?v=4)](https://github.com/dlarin88 "dlarin88 (1 commits)")

### Embed Badge

![Health badge](/badges/tmsolution-phpws/health.svg)

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

###  Alternatives

[zfr/zfr-cors

Zend Framework module that let you deal with CORS requests

611.2M3](/packages/zfr-zfr-cors)[bitwasp/stratum

library for interfacing with stratum servers, used to serve both bitcoin mining and electrum clients

1927.5k](/packages/bitwasp-stratum)

PHPackages © 2026

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