diff --git a/src/Factory.php b/src/Factory.php index 7e7f6ca..b44e1ec 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -67,8 +67,8 @@ public function __construct(LoopInterface $loop = null, $binary = null) $this->loop = $loop ?: Loop::get(); $this->bin = $binary === null ? $this->php() : $binary; - // use socket I/O for Windows only, use faster process pipes everywhere else - $this->useSocket = \DIRECTORY_SEPARATOR === '\\'; + // use socket I/O for Windows on PHP < 8.0 only, use faster process pipes everywhere else + $this->useSocket = \DIRECTORY_SEPARATOR === '\\' && \PHP_VERSION_ID < 80000; } /** @@ -235,7 +235,11 @@ private function openProcessIo($filename, $flags = null) $cwd = __DIR__ . '/../res'; $worker = \basename($worker); } - $command = 'exec ' . \escapeshellarg($this->bin) . ' ' . escapeshellarg($worker); + + $command = \escapeshellarg($this->bin) . ' ' . escapeshellarg($worker); + if (\DIRECTORY_SEPARATOR !== '\\') { + $command = 'exec ' . $command; + } // Try to get list of all open FDs (Linux/Mac and others) $fds = @\scandir('/dev/fd'); @@ -246,7 +250,7 @@ private function openProcessIo($filename, $flags = null) // @codeCoverageIgnoreStart if ($fds === false) { $fds = array(); - for ($i = 0; $i <= 1024; ++$i) { + for ($i = 0; $i <= 1024 && \DIRECTORY_SEPARATOR !== '\\'; ++$i) { $copy = @\fopen('php://fd/' . $i, 'r'); if ($copy !== false) { $fds[] = $i; @@ -256,10 +260,10 @@ private function openProcessIo($filename, $flags = null) } // @codeCoverageIgnoreEnd - // launch process with default STDIO pipes, but inherit STDERR + // launch process with default STDIO pipes (or sockets on Windows with PHP 8+), but inherit STDERR $pipes = array( - array('pipe', 'r'), - array('pipe', 'w'), + \DIRECTORY_SEPARATOR === '\\' ? array('socket') : array('pipe', 'r'), + \DIRECTORY_SEPARATOR === '\\' ? array('socket') : array('pipe', 'w'), \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'w') ); diff --git a/tests/FunctionalDatabaseTest.php b/tests/FunctionalDatabaseTest.php index 8eedc2d..c4acb58 100644 --- a/tests/FunctionalDatabaseTest.php +++ b/tests/FunctionalDatabaseTest.php @@ -12,7 +12,7 @@ class FunctionalDatabaseTest extends TestCase { public function provideSocketFlag() { - if (DIRECTORY_SEPARATOR === '\\') { + if (DIRECTORY_SEPARATOR === '\\' && PHP_VERSION_ID < 80000) { return [[true]]; } else { return [[false], [true]]; @@ -34,7 +34,7 @@ public function providePhpBinaryAndSocketFlag() null, true ] - ], DIRECTORY_SEPARATOR === '\\' ? [] : [ + ], DIRECTORY_SEPARATOR === '\\' && PHP_VERSION_ID < 80000 ? [] : [ [ null, false