Skip to content

Conversation

addshore
Copy link

Apparently PHP_BINARY can sometimes be an empty string.
If this is the case, we don't want to use it.
Doing so results in Unable to execute ''.

A reproduction example for when this happens is included below:

  • Create both files
  • chmod +x repro2.php
  • php repro.php
  • You'll see that PHP_BINARY is "".

If you run repro2.php directly you'll likely then see it with a correct path

repro.php:

<?php

$descriptorspec = array(
	0 => array("pipe", "r"),   // stdin is a pipe that the child will read from
	1 => array("pipe", "w"),   // stdout is a pipe that the child will write to
	2 => array("pipe", "w")    // stderr is a pipe that the child will write to
);
flush();
$process = proc_open(__DIR__ . '/repro2.php', $descriptorspec, $pipes, __DIR__, array());
if (is_resource($process)) {
	while ( ( $c = fgetc($pipes[1]) ) !== false ) {
		echo $c;
		flush();
	}
}
echo proc_get_status($process)['exitcode'];

repro2.php:

#!/usr/bin/env php
<?php

var_dump(PHP_BINARY);

I discovered this while trying to upgrade https://github.com/addwiki/addwiki from the old jakub-onderka/php-parallel-lint package to "php-parallel-lint/php-parallel-lint": "^1.2".
This is a monorepo, and there is a convenience script for running things such as linters in all sub packages.
This makes use of proc_open which seems to have something to do with this issue.

@jrfnl
Copy link
Collaborator

jrfnl commented Feb 16, 2021

@addshore I've just tried to reproduce this on Windows, but couldn't even get the script to run properly.

It did make me wonder about this line:

$process = proc_open(__DIR__ . '/repro2.php', $descriptorspec, $pipes, __DIR__, array());

You are passing an empty array as $env at the end. The proc_open() docs say this about the env parameter:

env

An array with the environment variables for the command that will be run, or null to use the same environment as the current PHP process

So, this leaves me wondering if removing the empty array in your call to proc_open() wouldn't automatically fix it.... ?

@addshore
Copy link
Author

@jrfnl thanks for spotting that! This does indeed fix my issue.

@addshore addshore closed this Feb 16, 2021
@jrfnl
Copy link
Collaborator

jrfnl commented Feb 16, 2021

@addshore Glad to hear it and thanks for letting me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants