/**
  * Loads to configuration from the daemon options and installs signal
  * handlers.
  *
  * @param DaemonOptions $daemonOptions
  */
 private function setupDaemon(DaemonOptions $daemonOptions)
 {
     $this->requestCount = 0;
     $this->requestLimit = $daemonOptions->getOption(DaemonOptions::REQUEST_LIMIT);
     $this->memoryLimit = $daemonOptions->getOption(DaemonOptions::MEMORY_LIMIT);
     $timeLimit = $daemonOptions->getOption(DaemonOptions::TIME_LIMIT);
     if (DaemonOptions::NO_LIMIT !== $timeLimit) {
         pcntl_alarm($timeLimit);
     }
     $this->installSignalHandlers();
 }
 /**
  * Tests that the daemon options object works properly.
  */
 public function testDaemonOptions()
 {
     $logger = new NullLogger();
     $requestLimit = 10;
     $memoryLimit = $timeLimit = DaemonOptions::NO_LIMIT;
     // implicit as not passed in options array
     $options = new DaemonOptions([DaemonOptions::LOGGER => $logger, DaemonOptions::REQUEST_LIMIT => $requestLimit]);
     $this->assertSame($logger, $options->getOption(DaemonOptions::LOGGER));
     $this->assertEquals($requestLimit, $options->getOption(DaemonOptions::REQUEST_LIMIT));
     $this->assertEquals($memoryLimit, $options->getOption(DaemonOptions::MEMORY_LIMIT));
     $this->assertEquals($timeLimit, $options->getOption(DaemonOptions::TIME_LIMIT));
 }
 /**
  * Wait for connections in the pool to become readable. Create connection
  * handlers for new connections and trigger the ready method when there is
  * data for the handlers to receive. Clean up closed connections.
  */
 private function processConnectionPool()
 {
     $readableConnections = $this->connectionPool->getReadableConnections(5);
     foreach ($readableConnections as $id => $connection) {
         if (!isset($this->connectionHandlers[$id])) {
             $this->connectionHandlers[$id] = $this->connectionHandlerFactory->createConnectionHandler($this->kernel, $connection);
         }
         try {
             $dispatchedRequests = $this->connectionHandlers[$id]->ready();
             $this->incrementRequestCount($dispatchedRequests);
         } catch (UserlandDaemonException $exception) {
             $this->daemonOptions->getOption(DaemonOptions::LOGGER)->error($exception->getMessage());
         }
         if ($this->connectionHandlers[$id]->isClosed()) {
             unset($this->connectionHandlers[$id]);
         }
     }
 }