2017 © Pedro Peláez
 

library websockets

WebSocket implementation

image

stegru/websockets

WebSocket implementation

  • Saturday, August 29, 2015
  • by ste
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP WebSockets

A PHP implementation of the WebSocket protocol., (*1)

Quick Start

Install:, (*2)

$ composer require stegru/websockets

Simple example:, (*3)

<?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:, (*4)

$ php ws.php 

Browser:, (*5)

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

Output:, (*6)

Welcome!
!olleh

The Versions

29/08 2015

dev-master

9999999-dev https://github.com/stegru/php-websockets

WebSocket implementation

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Steve Grundell

websockets