I'm trying to execute a separate PHP script from within a PHP page. After some research, I found that it is possible using the exec()
function.
I also referenced this SO solution to find the path of the php binary. So my full command looks like this:
$file_path = '192.168.1.13:8080/doSomething.php';
$cmd = PHP_BINDIR.'/php '.$file_path; // PHP_BINDIR prints /usr/local/bin
exec($cmd, $op, $er);
echo $er; // prints 127 which turns out to be invalid path/typo
doSomething.php
echo "Hi there!";
I know $file_path
is a correct path because if I open its value; i.e. 192.168.1.13:8080/doSomething.php
, I do get "Hi there!" printed out. This makes me assume that PHP_BINDIR.'/php'
is wrong.
Should I be trying to get the path of the php binary in some other way?