I have an external php script named external.php
which includes this:
<?php
echo 'External Output';
?>
When I run that on command line with command:
php external.php
I get output as
External Output
But when the same script I execute from my browser's php file named index.php
which has this code:
<?php
$exe=exec('php external.php',$out,$ret);
print_r($out);
?>
Then I get no output.
When I modify it as:
<?php
$exe=exec('php external.php 2>&1',$out,$ret);
print_r($out);
?>
Then I get this output:
php: /opt/lampp/lib/libxml2.so.2: version `LIBXML2_2.9.0' not found (required by php)
My question is, how can I execute that "external.php" file in commandline from index.php and get output on my browser (i.e. on index.php) ? I have tried system() function too, it doesn't work as well.
Edit: I cannot include
the external.php in index.php because external.php can take lot of time to execute (more than 10 hours).
Edit#2 Solved it, giving the full path to PHP solved the problem.
Here is an example:
<?php
$exe=exec('full/path/to/php /full/path/to/external.php',$out,$ret);
print_r($out);
?>
Thankyou Oleg and Scopey for giving me some hint help.
Specify the full path of external.php:
<?php
$exe=exec('php /full/path/to/external.php',$out,$ret);
print_r($out);
?>
Try also specifying the full path to php on the command line and check that it works:
$/usr/bin/php "/full/path/to/external.php"
If that works, try it also in your php file:
<?php
$exe=exec('/usr/bin/php /full/path/to/external.php',$out,$ret);
print_r($out);
?>
Try running phpinfo()
from the command line. Often installations of PHP use a different PHP.ini for CLI usage. Running phpinfo()
will show you the location of the ini file in use. It appears as though this ini might not be configured properly for your installation (as a guess)