Reputation: 12459
I have a PHP script that calls a command-line utility via exec. It works fine on my (Xubuntu linux based) development machine, but not in my (CentOS linux based) testing environment on the production server.
In order to isolate the error, I have created the following test script:
<?php
$command = "echo test";
$output = array();
exec($command, $output);
foreach ($output as $line)
{
echo "new line: " . $line . "\n";
}
echo "done";
?>
When I run this via php test.php
, I get the following output.
done
I.e. it seems that the exec command does not produce any output, as is the case in my real script.
What is the cause of this behavior or where to look for further information?
Upvotes: 0
Views: 1213
Reputation: 2270
Many web servers will disable some PHP functions by default (some will also not allow you to modify those defaults). If you have a halfway decent webserver you should be able to edit the php.ini file. Look for a line which reads something like:
disable_functions =exec,passthru,shell_exec [ etc... ]
If you see that, remove exec fromt he list and restart your web service.
Upvotes: 1