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\Command;
 4: 
 5: use PHPFastCGI\FastCGIDaemon\DaemonFactory;
 6: use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
 7: use PHPFastCGI\FastCGIDaemon\KernelInterface;
 8: use Symfony\Component\Console\Command\Command;
 9: use Symfony\Component\Console\Input\InputInterface;
10: use Symfony\Component\Console\Input\InputOption;
11: use Symfony\Component\Console\Output\OutputInterface;
12: use Symfony\Component\Console\Logger\ConsoleLogger;
13: 
14: class DaemonRunCommand extends Command
15: {
16:     const DEFAULT_NAME        = 'run';
17:     const DEFAULT_DESCRIPTION = 'Run the FastCGI daemon';
18: 
19:     /**
20:      * @var DaemonFactoryInterface
21:      */
22:     private $daemonFactory;
23: 
24:     /**
25:      * @var KernelInterface|callable
26:      */
27:     private $kernel;
28: 
29:     /**
30:      * Constructor.
31:      *
32:      * @param KernelInterface|callable $kernel        The kernel to be given to the daemon
33:      * @param DaemonFactoryInterface   $daemonFactory The factory to use to create the daemon
34:      * @param string                   $name          The name of the daemon run command
35:      * @param string                   $description   The description of the daemon run command
36:      */
37:     public function __construct($kernel, DaemonFactoryInterface $daemonFactory = null, $name = null, $description = null)
38:     {
39:         $daemonFactory = $daemonFactory ?: new DaemonFactory;
40:         $name          = $name          ?: self::DEFAULT_NAME;
41:         $description   = $description   ?: self::DEFAULT_DESCRIPTION;
42: 
43:         parent::__construct($name);
44: 
45:         $this
46:             ->setDescription($description)
47:             ->addOption('port', null, InputOption::VALUE_OPTIONAL, 'TCP port to listen on (if not present, daemon will listen on FCGI_LISTENSOCK_FILENO)')
48:             ->addOption('host', null, InputOption::VALUE_OPTIONAL, 'TCP host to listen on');
49: 
50:         $this->daemonFactory = $daemonFactory;
51: 
52:         if (!$kernel instanceof KernelInterface && !is_callable($kernel)) {
53:             throw new \InvalidArgumentException('Kernel parameter must be an instance of KernelInterface or a callable');
54:         }
55: 
56:         $this->kernel = $kernel;
57:     }
58: 
59:     /**
60:      * {@inheritdoc}
61:      */
62:     protected function execute(InputInterface $input, OutputInterface $output)
63:     {
64:         $port = $input->getOption('port');
65:         $host = $input->getOption('host');
66: 
67:         if (null !== $port) {
68:             // If we have the port, create a TCP daemon
69: 
70:             if (null !== $host) {
71:                 $daemon = $this->daemonFactory->createTcpDaemon($this->kernel, $port, $host);
72:             } else {
73:                 $daemon = $this->daemonFactory->createTcpDaemon($this->kernel, $port);
74:             }
75:         } elseif (null !== $host) {
76:             // If we have the host but not the port, we cant create a TCP daemon - throw exception
77:             throw new \InvalidArgumentException('TCP port option must be set if host option is set');
78:         } else {
79:             // With no host or port, listen on FCGI_LISTENSOCK_FILENO (default)
80:             $daemon = $this->daemonFactory->createDaemon($this->kernel);
81:         }
82: 
83:         $daemon->setLogger(new ConsoleLogger($output));
84: 
85:         $daemon->run();
86:     }
87: }
88: 
API documentation generated by ApiGen