Overview

Namespaces

  • PHPFastCGI
    • FastCGIDaemon
      • Command
      • Connection
      • ConnectionHandler
      • Exception
      • Http

Classes

  • PHPFastCGI\FastCGIDaemon\ApplicationFactory
  • PHPFastCGI\FastCGIDaemon\CallbackWrapper
  • PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand
  • PHPFastCGI\FastCGIDaemon\Connection\StreamSocketConnection
  • PHPFastCGI\FastCGIDaemon\Connection\StreamSocketConnectionPool
  • PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandler
  • PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandlerFactory
  • PHPFastCGI\FastCGIDaemon\Daemon
  • PHPFastCGI\FastCGIDaemon\DaemonFactory
  • PHPFastCGI\FastCGIDaemon\Http\Request

Interfaces

  • PHPFastCGI\FastCGIDaemon\ApplicationFactoryInterface
  • PHPFastCGI\FastCGIDaemon\Connection\ConnectionInterface
  • PHPFastCGI\FastCGIDaemon\Connection\ConnectionPoolInterface
  • PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandlerFactoryInterface
  • PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandlerInterface
  • PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface
  • PHPFastCGI\FastCGIDaemon\DaemonInterface
  • PHPFastCGI\FastCGIDaemon\Http\RequestInterface
  • PHPFastCGI\FastCGIDaemon\KernelInterface

Exceptions

  • PHPFastCGI\FastCGIDaemon\Exception\ConnectionException
  • PHPFastCGI\FastCGIDaemon\Exception\DaemonException
  • PHPFastCGI\FastCGIDaemon\Exception\ProtocolException
  • PHPFastCGI\FastCGIDaemon\Exception\ShutdownException
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: namespace PHPFastCGI\FastCGIDaemon;
 4: 
 5: use PHPFastCGI\FastCGIDaemon\Connection\ConnectionPoolInterface;
 6: use PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandlerFactoryInterface;
 7: use PHPFastCGI\FastCGIDaemon\Exception\ShutdownException;
 8: use Psr\Log\LoggerAwareInterface;
 9: use Psr\Log\LoggerAwareTrait;
10: use Psr\Log\LoggerInterface;
11: use Psr\Log\NullLogger;
12: 
13: /**
14:  * The standard implementation of the DaemonInterface is constructed from a
15:  * connection pool and a factory class to generate connection handlers.
16:  */
17: class Daemon implements DaemonInterface, LoggerAwareInterface
18: {
19:     use LoggerAwareTrait;
20: 
21:     /**
22:      * @var ConnectionPoolInterface
23:      */
24:     private $connectionPool;
25: 
26:     /**
27:      * @var ConnectionHandlerFactoryInterface
28:      */
29:     private $connectionHandlerFactory;
30: 
31:     /**
32:      * Constructor.
33:      *
34:      * @param ConnectionPoolInterface           $connectionPool           The connection pool to accept connections from
35:      * @param ConnectionHandlerFactoryInterface $connectionHandlerFactory A factory class for producing connection handlers
36:      * @param LoggerInterface                   $logger                   A logger to use
37:      */
38:     public function __construct(ConnectionPoolInterface $connectionPool, ConnectionHandlerFactoryInterface $connectionHandlerFactory, LoggerInterface $logger = null)
39:     {
40:         $this->connectionPool           = $connectionPool;
41:         $this->connectionHandlerFactory = $connectionHandlerFactory;
42: 
43:         $this->setLogger((null === $logger) ? new NullLogger() : $logger);
44: 
45:         if ($this->connectionPool instanceof LoggerAwareInterface) {
46:             $this->connectionPool->setLogger($this->logger);
47:         }
48: 
49:         if ($this->connectionHandlerFactory instanceof LoggerAwareInterface) {
50:             $this->connectionHandlerFactory->setLogger($this->logger);
51:         }
52:     }
53: 
54:     /**
55:      * {@inheritdoc}
56:      */
57:     public function run()
58:     {
59:         declare(ticks = 1);
60: 
61:         pcntl_signal(SIGINT, function () {
62:             $this->connectionPool->shutdown();
63:             throw new ShutdownException('Received SIGINT, shutting down...');
64:         });
65: 
66:         try {
67:             while (1) {
68:                 $this->connectionPool->operate($this->connectionHandlerFactory, 5);
69:                 // @codeCoverageIgnoreStart
70:             }
71:             // @codeCoverageIgnoreEnd
72:         } catch (ShutdownException $exception) {
73:             $this->logger->notice($exception->getMessage());
74:         } catch (\RuntimeException $exception) {
75:             $this->logger->emergency($exception->getMessage());
76:             throw $exception;
77:         }
78:     }
79: }
80: 
API documentation generated by ApiGen