Skip to content

Instantly share code, notes, and snippets.

@jmoz
Created January 22, 2013 12:09
Show Gist options
  • Save jmoz/4594162 to your computer and use it in GitHub Desktop.
Save jmoz/4594162 to your computer and use it in GitHub Desktop.
Ratchet and Predis-async. (React and Redis).
<?php
use RatchetApp\Pusher;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new Pusher();
$loop->addPeriodicTimer(10, array($pusher, 'timedCallback'));
$client = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$client->connect(array($pusher, 'init'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8080, '0.0.0.0');
$webServer = new Ratchet\Server\IoServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
),
$webSock
);
echo "Pusher starting...\n";
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment