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.
Usually the binary is located here: /usr/bin/php5.
The default location for the php. ini file is: Ubuntu 16.04: /etc/php/7.0/apache2.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With