Web Sockets in PHP using Ratchet
JavaScript PHP
Switch branches/tags
Nothing to show
Permalink
Failed to load latest commit information.
app Initial commit Jul 22, 2013
bin Initial commit Jul 22, 2013
public Initial commit Jul 22, 2013
.gitignore Initial commit Jul 22, 2013
README.md Fixed formatting in README again Jul 22, 2013
composer.json Initial commit Jul 22, 2013

README.md

Websocket Example in PHP using Ratchet

This is a small example (http://socketo.me/docs/push) of how to use Ratchet to do push/pull in a web app with Slim.

Dependencies

  • Ratchet
  • ZeroMQ (see below)
  • Slim

Usage

  1. Install dependencies

     $ composer install
    
  2. Run the ws server

     $ php bin/push-server.php
    
  3. Point a browser tab at the app (e.g. http://localhost/ws-example)

  4. Point a second tab at the same address and open your js console

  5. Post something in the first tab and check the result in the second tab.

Installing ZeroMQ

  1. Install ZeroMQ http://www.zeromq.org/area:download
  2. Install the PHP bindings http://www.zeromq.org/bindings:php
  3. On Windows:
    • Copy libzmq.dll into your php directory (e.g. C:\wamp\bin\php\php5.3.8)
    • Copy the appropriate version of php_zmq.dll to your php extension directory (e.g. C:\wamp\bin\php\php5.3.8\ext)

Some useful links

Ratchet

ZeroMQ

JS libraries

WAMP (Web Socket Messaging Protocal Specification)

Get ZeroMQ Version in PHP

From http://zguide.zeromq.org/php:zversion

<?php
/* Report 0MQ version
 *
 * @author Ian Barber <ian(dot)barber(at)gmail(dot)com>
 */

if (class_exists("ZMQ") && defined("ZMQ::LIBZMQ_VER")) {
echo ZMQ::LIBZMQ_VER, PHP_EOL;
}