如何在它所在的服务器上获取 php 二进制文件的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18656678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:58:32  来源:igfitidea点击:

How to get path of the php binary on server where it is located

phpbinaryinstallationproduction-environmentinstallation-path

提问by Ponting

I am using the execcommand as below in PHP :

exec在 PHP 中使用如下命令:

exec("/usr/bin/php /path/to/Notification.php >> /path/to/log_file.log 2>&1 &");

In my local environment (MAMP), I know the PHP installation path, so I can replace /usr/bin/phpwith /Applications/MAMP/bin/php/php5.4.10/bin/php. But I don't know where the PHP installation (PHP binary) is located on the production server.

在我的本地环境(MAMP)中,我知道PHP安装路径,所以我可以替换/usr/bin/php/Applications/MAMP/bin/php/php5.4.10/bin/php. 但我不知道 PHP 安装(PHP 二进制文件)在生产服务器上的位置。

回答by alexg

It's usually /usr/bin/phpbut you could try to capture and parse the output of the command 'whereis php' or 'which php''.

通常,/usr/bin/php但您可以尝试捕获和解析命令“ whereis php”或“ which php'”的输出。

Or better yet, use the constant PHP_BINARYif it is available. Have a look here.

或者更好的是,使用常量(PHP_BINARY如果可用)。看看这里

回答by Gras Double

Most of the time, the PHP_BINARYpredefined constantshould do the job.

大多数情况下,PHP_BINARY预定义的常量应该可以完成这项工作。

If you need something more developed, you can make use of Symfony's Process component, by using its PhpExecutableFinderclass:

如果你需要更多的开发,你可以使用 Symfony 的Process 组件,通过使用它的PhpExecutableFinder类:

// composer require symfony/process

use Symfony\Component\Process\PhpExecutableFinder;

(new PhpExecutableFinder)->find();

回答by Prashant D. Kamthe

Try these two steps: updatedb (only needs to be run once to update the locate index) locate php | grep -P "/php$"

试试这两个步骤:updatedb(只需要运行一次来​​更新locate index) locate php | grep -P "/php$"

The locate command should show you all files on the server with "php" in their filename or folder name. The "grep" pipe filters down the results down to just things that end in "/php".

locate 命令应该显示服务器上所有文件名或文件夹名中带有“php”的文件。“grep”管道将结果过滤为以“/php”结尾的内容。