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

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

webmotor/phpws
==============

WebSocket Server and Client library for PHP

018PHP

Since Nov 21Pushed 8y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (5)Used By (0)

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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.9% 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/75efd2f692107c6f5e9e477ecd1df0334dd44921f58c1c35ccc6211c977176df?d=identicon)[oprokidnev](/maintainers/oprokidnev)

---

Top Contributors

[![Devristo](https://avatars.githubusercontent.com/u/1564257?v=4)](https://github.com/Devristo "Devristo (152 commits)")[![DannyWilkerson](https://avatars.githubusercontent.com/u/6262325?v=4)](https://github.com/DannyWilkerson "DannyWilkerson (4 commits)")[![oprokidnev](https://avatars.githubusercontent.com/u/1657922?v=4)](https://github.com/oprokidnev "oprokidnev (2 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/webmotor-phpws/health.svg)

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

###  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)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

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

78126.4M414](/packages/react-http)

PHPackages © 2026

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