Skip to content

Commit 9db3889

Browse files
committed
Add support for custom fd
1 parent 64ebe76 commit 9db3889

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/Command/DaemonRunCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPFastCGI\FastCGIDaemon\Command;
44

5+
use PHPFastCGI\FastCGIDaemon\DaemonInterface;
56
use PHPFastCGI\FastCGIDaemon\DaemonOptions;
67
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
78
use PHPFastCGI\FastCGIDaemon\KernelInterface;
@@ -48,6 +49,7 @@ public function __construct(KernelInterface $kernel, DriverContainerInterface $d
4849
->setDescription($description)
4950
->addOption('port', null, InputOption::VALUE_OPTIONAL, 'TCP port to listen on (if not present, daemon will listen on FCGI_LISTENSOCK_FILENO)')
5051
->addOption('host', null, InputOption::VALUE_OPTIONAL, 'TCP host to listen on')
52+
->addOption('fd', null, InputOption::VALUE_OPTIONAL, 'File descriptor to listen on - defaults to FCGI_LISTENSOCK_FILENO', DaemonInterface::FCGI_LISTENSOCK_FILENO)
5153
->addOption('request-limit', null, InputOption::VALUE_OPTIONAL, 'The maximum number of requests to handle before shutting down')
5254
->addOption('memory-limit', null, InputOption::VALUE_OPTIONAL, 'The memory limit on the daemon instance before shutting down')
5355
->addOption('time-limit', null, InputOption::VALUE_OPTIONAL, 'The time limit on the daemon in seconds before shutting down')
@@ -86,6 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8688
{
8789
$port = $input->getOption('port');
8890
$host = $input->getOption('host');
91+
$fd = $input->getOption('fd');
8992

9093
$daemonOptions = $this->getDaemonOptions($input, $output);
9194

@@ -100,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
100103
throw new \InvalidArgumentException('TCP port option must be set if host option is set');
101104
} else {
102105
// With no host or port, listen on FCGI_LISTENSOCK_FILENO (default)
103-
$daemon = $daemonFactory->createDaemon($this->kernel, $daemonOptions);
106+
$daemon = $daemonFactory->createDaemon($this->kernel, $daemonOptions, $fd);
104107
}
105108

106109
$daemon->run();

src/DaemonFactoryInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
interface DaemonFactoryInterface
1111
{
1212
/**
13-
* Create a FastCGI daemon listening on FCGI_LISTENSOCK_FILENO.
13+
* Create a FastCGI daemon listening on file descriptor.
1414
*
15-
* @param KernelInterface $kernel The kernel to use for the daemon
16-
* @param DaemonOptionsInterface $options The daemon configuration
15+
* @param KernelInterface $kernel The kernel to use for the daemon
16+
* @param DaemonOptions|DaemonOptionsInterface $options The daemon configuration
17+
* @param int $fd file descriptor for listening defaults to FCGI_LISTENSOCK_FILENO
1718
*
1819
* @return DaemonInterface The FastCGI daemon
1920
*/
20-
public function createDaemon(KernelInterface $kernel, DaemonOptions $options);
21+
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO);
2122

2223
/**
2324
* Create a FastCGI daemon listening on a given address. The default host is

src/Driver/Userland/UserlandDaemonFactory.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,23 @@
1515
class UserlandDaemonFactory implements DaemonFactoryInterface
1616
{
1717
/**
18-
* Create a FastCGI daemon listening on FCGI_LISTENSOCK_FILENO using the
18+
* Create a FastCGI daemon listening on file descriptor using the
1919
* userland FastCGI implementation.
2020
*
2121
* @param KernelInterface $kernel The kernel to use for the daemon
2222
* @param DaemonOptions $options The daemon configuration
23+
* @param int $fd file descriptor for listening defaults to FCGI_LISTENSOCK_FILENO
2324
*
2425
* @return UserlandDaemon
2526
*
2627
* @codeCoverageIgnore The FastCGI daemon
2728
*/
28-
public function createDaemon(KernelInterface $kernel, DaemonOptions $options)
29+
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO)
2930
{
30-
$socket = fopen('php://fd/'.DaemonInterface::FCGI_LISTENSOCK_FILENO, 'r');
31+
$socket = fopen('php://fd/'.$fd, 'r');
3132

3233
if (false === $socket) {
33-
throw new \RuntimeException('Could not open FCGI_LISTENSOCK_FILENO');
34+
throw new \RuntimeException('Could not open ' . $fd);
3435
}
3536

3637
return $this->createDaemonFromStreamSocket($kernel, $options, $socket);

0 commit comments

Comments
 (0)