stegru/websockets

WebSocket implementation

Maintainers

Package info

github.com/stegru/php-websockets

pkg:composer/stegru/websockets

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2015-08-29 11:53 UTC

This package is not auto-updated.

Last update: 2026-05-10 03:38:53 UTC


README

#PHP WebSockets A PHP implementation of the WebSocket protocol.

##Quick Start

Install:

$ composer require stegru/websockets

Simple example:

<?php
require_once('vendor/autoload.php');

use WebSockets\Common\Event;
use WebSockets\Server\WebSocketServer;

$ws = new WebSocketServer();

$ws->addEventListener(function (Event $e) {

    switch ($e->eventId) {
        case WebSocketServer::EVENT_CONNECTED:
            $e->connection->sendMessage("Welcome!");
            break;

        case WebSocketServer::EVENT_MESSAGE:
            $e->connection->sendMessage(strrev($e->message));
            break;
    }
});

$ws->start();

Run:

$ php ws.php 

Browser:

var ws = new WebSocket("ws://localhost:8088/socketserver", "hello");
ws.onmessage = function(e) { console.log(e.data); }
ws.send("hello!");

Output:

Welcome!
!olleh