Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP detect if shell_exec() command failed

I'm running the ffmpeg command within PHP's shell_exec() to convert several videos in a list. Is there anyway to detect if an error happened while the video was being converted (or atleast verify it fully completed the conversion)?

I don't want to stop converting other videos if an error happens, just the ability to record the error.

<?php
    shell_exec('ffmpeg -i downloads/flv/file1.flv -vcodec libvpx -acodec libvorbis downloads/webm/file1.webm');

    if(error) {
     //run a command here to report the error (ie. MySQL or email)
    }
?>
like image 348
floatleft Avatar asked Dec 27 '22 12:12

floatleft


1 Answers

Capture the exit code with another system call function like exec:

exec('ffmpeg ...', $output, $return);

if ($return != 0) {
    // an error occurred
}

Any decent utility will exit with a code other than 0 on error.

like image 172
deceze Avatar answered Jan 09 '23 03:01

deceze