Skip to content

Commit 2738d00

Browse files
committed
feature #28303 [Process] Add relative path support for PHP_BINARY env var of PhpExecutableFinder (maidmaid)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Process] Add relative path support for PHP_BINARY env var of PhpExecutableFinder | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | / | License | MIT | Doc PR | / At the moment, only the absolute path for PHP_BINARY env var works, for instance : ``` $ PHP_BINARY=/usr/bin/php7.2 php bin/console server:run [OK] Server listening on http://127.0.0.1:8000 $ PHP_BINARY=php7.2 php bin/console server:run [ERROR] Unable to find the PHP binary. ``` This PR makes possible the second command. Commits ------- 52ed988 Add relative path support for PHP_BINARY env var of PhpExecutableFinder
2 parents a0e21f8 + 52ed988 commit 2738d00

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Symfony/Component/Process/PhpExecutableFinder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ public function find($includeArgs = true)
3737
{
3838
if ($php = getenv('PHP_BINARY')) {
3939
if (!is_executable($php)) {
40-
return false;
40+
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
41+
if ($php = strtok(exec($command.' '.escapeshellarg($php)), PHP_EOL)) {
42+
if (!is_executable($php)) {
43+
return false;
44+
}
45+
} else {
46+
return false;
47+
}
4148
}
4249

4350
return $php;

0 commit comments

Comments
 (0)