Skip to content

Commit 389fe02

Browse files
authored
Merge pull request #49 from donatj/fixup/descriptorHandlingFixup
Fix up the descriptor handling a pinch
2 parents c98bc85 + 070ab75 commit 389fe02

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/MockWebServer.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function start() : void {
8383
throw new Exceptions\ServerException("Failed to start server. Is something already running on port {$this->port}?");
8484
}
8585

86-
register_shutdown_function(function() {
86+
register_shutdown_function(function () {
8787
if( $this->isRunning() ) {
8888
$this->stop();
8989
}
@@ -287,8 +287,17 @@ private function startServer( string $fullCmd ) {
287287
$env = null;
288288
$cwd = null;
289289

290-
$output = tmpfile();
291-
$process = proc_open($fullCmd, [fopen('php://stdin', 'r'), $output, $output], $pipes, $cwd, $env, [
290+
$stdin = fopen('php://stdin', 'rb');
291+
$stdoutf = tempnam(sys_get_temp_dir(), 'MockWebServer.stdout');
292+
$stderrf = tempnam(sys_get_temp_dir(), 'MockWebServer.stderr');
293+
294+
$descriptorSpec = [
295+
0 => $stdin,
296+
1 => [ 'file', $stdoutf, 'a' ],
297+
2 => [ 'file', $stderrf, 'a' ],
298+
];
299+
300+
$process = proc_open($fullCmd, $descriptorSpec, $pipes, $cwd, $env, [
292301
'suppress_errors' => false,
293302
'bypass_shell' => true,
294303
]);
@@ -297,7 +306,7 @@ private function startServer( string $fullCmd ) {
297306
return $process;
298307
}
299308

300-
throw new Exceptions\ServerException("Error starting server");
309+
throw new Exceptions\ServerException('Error starting server');
301310
}
302311

303312
}

0 commit comments

Comments
 (0)