I have this line of code to execute a background task (convert several pngs to jpg)
exec("nohup path/to/php path/to/convertToJpg.php >> path/to/convert_to_jpg.log > /dev/null &");
Now I am writing the convertToJpg.php
script and I can't figure out how to output information from there so that it will be logged into the convert_to_jpg.log
.
When I try to google it all I come up with is how to call a php script from exec
or shell_exec
, since the words used to describe the two situations is almost the same.
For Clarification
An extra quote got into my code when copying it over to SO. I have fixed it. In my original code the convertToJpg.php
is being called as expected, confirmed by error_logs
placed in it to check.
A couple answers have pointed to the $output
argument in exec()
. As I understand it, that totally defeats the purpose of shell redirection using the >> path/to/convert_to_jpg.log
.
My question is not how to get the output from the exec()
command, but what code do I use to actually output(verb) from the convert_to_jpg.log
More Clarification
If I call
exec("nohup path/to/php path/to/convertToJpg.php >> path/to/convert_to_jpg.log > /dev/null &");
or
$results = shell_exec("path/to/php path/to/convertToJpg.php > /dev/null");
echo $results;
or
$results = "";
exec("path/to/php path/to/convertToJpg.php > /dev/null", $results);
print_r($results);
It doesn't matter which one.
Here is convertToJpg.php
<?php
echo "Will this be in $results?"; // No, this did not end up in results.
error_log("error logs are being logged, so I know that this php file is being called");
//I have tested echo, but that does not work.
//What php function do I use so that a string will be captured in the $output of an exec() call?
?>