Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (27 sloc) 1.01 KB

Getting Started

Starting a Server

The first thing you'll want to do to serve WebSockets from PHP is start a WebSockets server. Wrench provides a simple Server class that implements the most recent version of the WebSockets protocol. Subclassing the Server class is encouraged: see WebSocketBasicServer for an example.

When you're ready for your server to start responding to requests, call $server->run():

use Wrench\BasicServer;

$server = new BasicServer('ws://localhost:8000', array(
    'allowed_origins' => array(
        'mysite.com',
        'mysite.dev.localdomain'
    )
));

// Logging is via PSR3
$logger = new Monolog\Logger('name');
$server->setLogger($logger);

// Register your applications here
$server->registerApplication('echo', new \Wrench\Examples\EchoApplication());
$server->registerApplication('chat', new \My\ChatApplication());

$server->run();
You can’t perform that action at this time.