/**
  * @throws Network\Socket\Exceptions\NoResourceException
  */
 public function run()
 {
     $timer = new Timer();
     $this->running = true;
     while ($this->running) {
         $timer->update();
         if ($this->signalHandler->getSignal() == SignalHandler::SIGNAL_HANDLER_SHUTDOWN) {
             $this->running = false;
             break;
         }
         $this->socketList->tryNewSocket($this->managementSocket->waitForConnection());
         foreach ($this->socketList as $k => $clientSocket) {
             $socketRead = socket_read($clientSocket, 2048);
             if ($socketRead === false) {
                 continue;
             }
             $request = new Request();
             $request->withHeaderString($socketRead);
             $this->managementServer->processRequest($request->getUri(), $request->getMethod());
             ob_start();
             $this->managementServer->prepareResponse();
             $response = ob_get_clean();
             @socket_write($clientSocket, $response, strlen($response));
             $this->managementClientThreads[$k] = new ClientThread($clientSocket, $request);
             //$this->managementClientThreads[$k]->start();
         }
         foreach ($this->managementClientThreads as $k => $clientThread) {
             $this->socketList->close($clientThread->getSocket());
             unset($this->managementClientThreads[$k]);
         }
         echo $timer->getElapsed() . "\r";
         //wait until 1 ms is over
         //performance tweek, DO NOT REMOVE
         $timer->adjust();
     }
 }
예제 #2
0
if (empty($loggerImpl) || !isset($loggerImpl["class"])) {
    $loggerImpl = "RIP\\Components\\Framework\\Core\\Logger";
} else {
    $loggerImpl = $loggerImpl["class"];
}
$logger = new $loggerImpl();
//******
//******
//Loading IRouter implementation
$routerImpl = $injectionConfig->get("framework.router");
if (empty($routerImpl) || !isset($routerImpl["class"])) {
    $routerImpl = "RIP\\Components\\Framework\\Core\\Router";
} else {
    $routerImpl = $routerImpl["class"];
}
$router = new $routerImpl($configFolder . "routes.json");
$injector->store("framework.router", $router);
//******
//******
//Boot RESTInPHP
$rip = new RESTInPHP($injector, $applicationConfig, $logger);
$rip->boot();
//******
//******
//Run RESTInPHP
$rip->run();
//******
//******
//Shut down RESTInPHP
$rip->shutdown();
//******