Example #1
0
    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
    $client = socket_accept($socket) or die("Could not accept incoming connection\n");
    $input = socket_read($client, 1024) or die("Could not read input\n");
    if ($input) {
        // Use input to run executor
        $data = serialize($app->setExecutor($executor->setInput(unserialize($input)))->execute());
        // Send response and close socket
        socket_write($client, $data, strlen($data)) or die("Could not write output\n");
        socket_close($client);
    }
});
// Run main loop
Ev::run();