*/ require_once __DIR__ . '/../../vendor/autoload.php'; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use ExChat\Server as ChatServer; use ExHttp\Server as ConnectionHandler; use SlideBuilder\Server as SlideServer; use SlideBuilder\Builder as SlideBuilder; use ExHttp\Router; use ExHttp\StaticFile; use EventConfig as EventBaseConfig; use ExHttp\SseMessage as EventMessage; $cfg = new \EventConfig(); $cfg->requireFeatures(EventBaseConfig::FEATURE_FDS); $loop = new React\EventLoop\ExtEventLoop($cfg); $documentRoot = getcwd(); /* Configure router, the router allows for callbacks to be executed on a route match. If no match is found then it will look to see if it can load a static file. */ $connections = []; $router = new ExHttp\Router(); $connectionHandler = new ConnectionHandler($router); $fileHandler = new StaticFile($documentRoot, $loop); $router->setFileHandler($fileHandler); $connectionHandler->on('close', function ($conn) use(&$connections) { foreach ($connections as $key => $data) { $connection = $data['conn']; if ($connection === $conn) { unset($connections[$key]);
<?php /** */ require_once __DIR__ . '/../../../vendor/autoload.php'; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use ExHttp\Server as ConnectionHandler; use ExDraw\Server as DrawServer; use ExHttp\Router; use ExHttp\StaticFile; $loop = new React\EventLoop\ExtEventLoop(); $documentRoot = getcwd(); $drawServer = new DrawServer(); $clientBootstrap = file_get_contents(__DIR__ . '/index.html'); /* Configure router, the router allows for callbacks to be executed on a route match. If no match is found then it will look to see if it can load a static file. */ $router = new ExHttp\Router(array("/" => function ($request, $response, $connection) use($clientBootstrap) { $response->setBody($clientBootstrap); $connection->send($response); $connection->close(); })); $fileHandler = new StaticFile($documentRoot, $loop); $router->setFileHandler($fileHandler); /* Websocket and HTTP Server Sockets */ $socketServer = new React\Socket\Server($loop);
<?php require __DIR__ . '/../vendor/autoload.php'; /** @var $loop \React\EventLoop\ExtEventLoop */ $cfg = new \EventConfig(); $cfg->requireFeatures(\EventConfig::FEATURE_FDS); $loop = new \React\EventLoop\ExtEventLoop($cfg); $dir = getcwd(); $fd = fopen($dir . DIRECTORY_SEPARATOR . 'test.dmg', "r"); stream_set_blocking($fd, 0); $stream = new \React\Stream\Stream($fd, $loop); $stream->on('data', function () { echo 'test' . PHP_EOL; }); $loop->addPeriodicTimer(0.01, function () { echo "Timer" . PHP_EOL; }); $loop->run();