ZF2 PHP WebSocket Server Factory v2.1 (Extended)

v2.2.1 2015-05-19 21:18 UTC

This package is not auto-updated.

Last update: 2024-05-11 15:24:44 UTC


Alt text

Protocol WebSocket (standard RFC 6455) is designed to solve any problems and the removal of restrictions communication between browser and server.It allows you to transfer any data to any domain, safe and almost without unnecessary network traffic.

The main advantages of this module is that you can create a variety of applications based on Zend Framework 2, where it is necessary to implement persistent connections. Thanks to one interface, you can create a variety of applications and run them on the same server. You can organize a chat, monitor live site visit, you can create real-time statistics and save it to DB (MySQL, Mongo..etc), you can organize the postal service in the likeness of Google. Yes, anything!



v2.2.1 [Request from AdamiecRadek]

  • Added support for changing default application namespace
  • Added support for multiple namespaces for applications
  • Hotfix for proper index in config


  • Fixed service locator which is got ApplicationFactory v2.1
  • Select client's application from console like php -q index.php websocket open <app>


  • Add "Chat" application as example
  • More advanced interface
  • Ability to create multiple applications and bind it to the same server
  • Detailed log of each ping server's
  • The ability to set the maximum number of connections to the server, the maximum number of connections per IP
  • Pre defined response errors for Linux, Win platforms (extended by their descriptions)
  • Ping using control frames such as PING PONG


  • Add logger


  • Add verbose turner (debug show\hide) (@see module.config.php)
  • Add socket function's exception handler
  • Fixed CLI stdout>> encoding
  • Add ViewHelper for a simple get server config params into view
// for example
echo $this->socket()->config('host'); // print


  • Console stdout>> while starting server


  • Fixes some problem with startup
  • Add console command interface for costom system commands (for example) php -q index.php websocket system "whoami" (Note for ZF2.2): if you have an exceptions Notice Undefined offset: 0 while starting console server please follow this:

vendor\ZF2\library\Zend\Mvc\View\Console\RouteNotFoundStrategy.php 381 and replace line by

$result .= isset($row[0]) ? $row[0] . "\n" : '';

It might be fixed until not fix in the next update. You're always can ask me for this module if you have write me issue

Installation and Running Server :

  1. First update your dependencies through composer. Then run to update dependency and update autoloader
php composer.phar require stanislav-web/zf2-websocket-server-factory
php composer.phar install -o
  1. That needs to be done is adding it to your application's list of active modules. Add module "WebSockets" in your application.config.php

  2. Perform module configuration file module.config.php

  3. Go to your shell command-line interface and type (running server as background): php -q index.php websocket open <app> (app like as your client application)

  4. Setup your Client-side script's to communicating with the server .. ws://host:port/websocket/open/

How can i do the Application ?

New application you can do according to the rules interface


As an example, you can see the implementation "Chat"


then call server from your cli controller


	    // get factory container
        $factory = new ApplicationFactory($this->getServiceLocator());

        // applications from response <app>
	    // get it @see /src/WebSockets/Application/Chat.php etc..

	    $client	= $request->getParam('app');

	    $app	= $factory->dispatch(ucfirst($client)); 
	    // bind events from application 
	    // ! must be implements of your every new Application
	    $app->bind('open', 'onOpen');
	    $app->bind('message', 'onMessage');
	    $app->bind('close', 'onClose');

	    // running server

In order to start using the module clone the repo in your vendor directory or add it as a submodule if you're already using git for your project: git clone vendor/WebSockets or git submodule add git clone vendor/WebSockets

The module will also be available as a Composer package soon.

Libraries used

Alt text