如何在它所在的服务器上获取 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
How to get path of the php binary on server where it is located
提问by Ponting
I am using the exec
command 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/php
with /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
回答by Gras Double
Most of the time, the PHP_BINARY
predefined 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”结尾的内容。