问题
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