Skip to content

Commit

Permalink
Merge pull request #49 from donatj/fixup/descriptorHandlingFixup
Browse files Browse the repository at this point in the history
Fix up the descriptor handling a pinch
  • Loading branch information
donatj authored Nov 28, 2022
2 parents c98bc85 + 070ab75 commit 389fe02
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/MockWebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function start() : void {
throw new Exceptions\ServerException("Failed to start server. Is something already running on port {$this->port}?");
}

register_shutdown_function(function() {
register_shutdown_function(function () {
if( $this->isRunning() ) {
$this->stop();
}
Expand Down Expand Up @@ -287,8 +287,17 @@ private function startServer( string $fullCmd ) {
$env = null;
$cwd = null;

$output = tmpfile();
$process = proc_open($fullCmd, [fopen('php://stdin', 'r'), $output, $output], $pipes, $cwd, $env, [
$stdin = fopen('php://stdin', 'rb');
$stdoutf = tempnam(sys_get_temp_dir(), 'MockWebServer.stdout');
$stderrf = tempnam(sys_get_temp_dir(), 'MockWebServer.stderr');

$descriptorSpec = [
0 => $stdin,
1 => [ 'file', $stdoutf, 'a' ],
2 => [ 'file', $stderrf, 'a' ],
];

$process = proc_open($fullCmd, $descriptorSpec, $pipes, $cwd, $env, [
'suppress_errors' => false,
'bypass_shell' => true,
]);
Expand All @@ -297,7 +306,7 @@ private function startServer( string $fullCmd ) {
return $process;
}

throw new Exceptions\ServerException("Error starting server");
throw new Exceptions\ServerException('Error starting server');
}

}

0 comments on commit 389fe02

Please sign in to comment.