Skip to content

[WIP] Use socket pipes on Windows with PHP 8+ #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -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')
);

Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionalDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand All @@ -34,7 +34,7 @@ public function providePhpBinaryAndSocketFlag()
null,
true
]
], DIRECTORY_SEPARATOR === '\\' ? [] : [
], DIRECTORY_SEPARATOR === '\\' && PHP_VERSION_ID < 80000 ? [] : [
[
null,
false
Expand Down