@@ -254,11 +254,12 @@ private function openProcessIo($filename, $flags = null)
254
254
\defined ('STDERR ' ) ? \STDERR : \fopen ('php://stderr ' , 'w ' )
255
255
);
256
256
257
- // do not inherit open FDs by explicitly overwriting existing FDs with dummy files
257
+ // do not inherit open FDs by explicitly overwriting existing FDs with dummy files.
258
+ // Accessing /dev/null with null spec requires PHP 7.4+, older PHP versions may be restricted due to open_basedir, so let's reuse STDERR here.
258
259
// additionally, close all dummy files in the child process again
259
260
foreach ($ fds as $ fd ) {
260
261
if ($ fd > 2 ) {
261
- $ pipes [$ fd ] = array ( ' file ' , ' /dev/ null ', ' r ' ) ;
262
+ $ pipes [$ fd ] = \ PHP_VERSION_ID >= 70400 ? [ ' null '] : $ pipes [ 2 ] ;
262
263
$ command .= ' ' . $ fd . '>&- ' ;
263
264
}
264
265
}
@@ -375,7 +376,7 @@ private function openSocketIo($filename, $flags = null)
375
376
private function which ($ bin )
376
377
{
377
378
foreach (\explode (\PATH_SEPARATOR , \getenv ('PATH ' )) as $ path ) {
378
- if (\is_executable ($ path . \DIRECTORY_SEPARATOR . $ bin )) {
379
+ if (@ \is_executable ($ path . \DIRECTORY_SEPARATOR . $ bin )) {
379
380
return $ path . \DIRECTORY_SEPARATOR . $ bin ;
380
381
}
381
382
}
@@ -396,20 +397,26 @@ private function resolve($filename)
396
397
397
398
/**
398
399
* @return string
400
+ * @codeCoverageIgnore Covered by `/tests/FunctionalExampleTest.php` instead.
399
401
*/
400
402
private function php ()
401
403
{
402
- // if this is the php-cgi binary, check if we can execute the php binary instead
403
- $ binary = \PHP_BINARY ;
404
- $ candidate = \str_replace ('-cgi ' , '' , $ binary );
405
- if ($ candidate !== $ binary && \is_executable ($ candidate )) {
406
- $ binary = $ candidate ; // @codeCoverageIgnore
404
+ $ binary = 'php ' ;
405
+ if (\PHP_SAPI === 'cli ' || \PHP_SAPI === 'cli-server ' ) {
406
+ // use same PHP_BINARY in CLI mode, but do not use same binary for CGI/FPM
407
+ $ binary = \PHP_BINARY ;
408
+ } else {
409
+ // if this is the php-cgi binary, check if we can execute the php binary instead
410
+ $ candidate = \str_replace ('-cgi ' , '' , \PHP_BINARY );
411
+ if ($ candidate !== \PHP_BINARY && @\is_executable ($ candidate )) {
412
+ $ binary = $ candidate ;
413
+ }
407
414
}
408
415
409
416
// if `php` is a symlink to the php binary, use the shorter `php` name
410
417
// this is purely cosmetic feature for the process list
411
- if (\realpath ($ this ->which ('php ' )) === $ binary ) {
412
- $ binary = 'php ' ; // @codeCoverageIgnore
418
+ if ($ binary !== ' php ' && \realpath ($ this ->which ('php ' )) === $ binary ) {
419
+ $ binary = 'php ' ;
413
420
}
414
421
415
422
return $ binary ;
0 commit comments