<?php /** * Create and bind socket */ $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); socket_bind($socket, '127.0.0.1', 8081) or die("Could not bind to socket\n"); socket_listen($socket, 3) or die("Could not set up socket listener\n"); /** * IO timeout watcher */ $timeout_watcher = new EvTimer(10.0, 0.0, function () use($socket) { socket_close($socket); Ev::stop(Ev::BREAK_ALL); }); /** * Load a new Scale Application */ $container = (require 'bootstrap.php'); $app = $container->constructInject('\\Scale\\Kernel\\Core\\Webapp'); $executor = $app->getExecutor(); $container->inform($executor); /** * Monitor socket read events in loop */ $read_watcher = new EvIo($socket, Ev::READ, function ($w, $re) use($socket, $app, $executor, $timeout_watcher) { // Stop timeout watcher $timeout_watcher->stop(); // Stop write watcher $w->stop(); // Connect and read from the client
/** * Stops the event loop, by stopping all the watchers and breaking out of the event loop. */ public function stop() { foreach ($this->watchers as $watcher) { $watcher->stop(); } \Ev::stop(\Ev::BREAK_ALL); }