@@ -254,11 +254,12 @@ private function openProcessIo($filename, $flags = null)
254254 \defined ('STDERR ' ) ? \STDERR : \fopen ('php://stderr ' , 'w ' )
255255 );
256256
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.
258259 // additionally, close all dummy files in the child process again
259260 foreach ($ fds as $ fd ) {
260261 if ($ fd > 2 ) {
261- $ pipes [$ fd ] = array ( ' file ' , ' /dev/ null ', ' r ' ) ;
262+ $ pipes [$ fd ] = \ PHP_VERSION_ID >= 70400 ? [ ' null '] : $ pipes [ 2 ] ;
262263 $ command .= ' ' . $ fd . '>&- ' ;
263264 }
264265 }
@@ -375,7 +376,7 @@ private function openSocketIo($filename, $flags = null)
375376 private function which ($ bin )
376377 {
377378 foreach (\explode (\PATH_SEPARATOR , \getenv ('PATH ' )) as $ path ) {
378- if (\is_executable ($ path . \DIRECTORY_SEPARATOR . $ bin )) {
379+ if (@ \is_executable ($ path . \DIRECTORY_SEPARATOR . $ bin )) {
379380 return $ path . \DIRECTORY_SEPARATOR . $ bin ;
380381 }
381382 }
@@ -396,20 +397,26 @@ private function resolve($filename)
396397
397398 /**
398399 * @return string
400+ * @codeCoverageIgnore Covered by `/tests/FunctionalExampleTest.php` instead.
399401 */
400402 private function php ()
401403 {
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+ }
407414 }
408415
409416 // if `php` is a symlink to the php binary, use the shorter `php` name
410417 // 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 ' ;
413420 }
414421
415422 return $ binary ;
0 commit comments