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

女生的网名这么多〃 提交于 2020-01-02 02:42:06

问题


I am using the exec command as below in 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.


回答1:


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

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




回答2:


Most of the time, the PHP_BINARY predefined constant should do the job.

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

// composer require symfony/process

use Symfony\Component\Process\PhpExecutableFinder;

(new PhpExecutableFinder)->find();


来源:https://stackoverflow.com/questions/18656678/how-to-get-path-of-the-php-binary-on-server-where-it-is-located

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!