I've got some PHP code that, among other things, uses system()
to call ffmpeg to encode a video. When I run this from a command line, I can redirect the output of the PHP script to a file in the usual way -- php mycode.php > mycode.log
-- and I get not only whatever print statements I call in PHP, but also the stuff produced by ffmpeg, which I want. All's well.
Now, however, I want to launch the PHP script in the background via a web page: I do some stuff on my site that causes this to run:
$the_command = "/bin/php $php_file_name > $log_file_name &";
$the_result = system($the_command, $retval);
This successfully runs my script in a background PHP process, and my videos are still getting encoded by ffmpeg. However, the only thing I'm getting in my redirected log file are the print statements in the script -- the output of the ffmpeg invocations are getting sent off to the ether somewhere. Is there any way I can get these saved in the log file as well?
Try this:
$the_command = "/bin/php $php_file_name > $log_file_name 2>&1";
IMHO - because the ffmpeg writes it's messages to stderr
. So, try something like:
$res = shell_exec("ffmpeg your_args >/tmp/log 2>&1 &");
this should redirect both stdout
and stderr
to the file.