wesleyw Posted September 27, 2013 Posted September 27, 2013 (edited) I've written a little program to automatic converting videos from a folder in linux using ffmpeg via shell_exec in php easy enough to do and worthwhile for the thousands of little clips I have I've got it to start the conversion in another process so as not to stall the php script until it's completed. However once it is completed I want another command to run (again in a separate process) and update a record in mysql. The & symbol works well but when you have two commands in shell_exec you use a ; to show a new command has started and putting an & in between doesn't work it fails to run the command and after is too late as the second command would run in a separate process but not the first so it would still delay the PHP script. Any ideas on how I could do this? shell_exec("ffmpeg input.avi output.mp4; php -e 'aphpfile.php'"); Any thoughts? I know I should be using escapeshellarg but this is only used by me at the moment. Wes Edited September 27, 2013 by wesleyw
penfold_99 Posted September 27, 2013 Posted September 27, 2013 When I have run two programs from the command line I have used && so try shell_exec("ffmpeg input.avi output.mp4 && php -e 'aphpfile.php'"); 1
wesleyw Posted September 27, 2013 Author Posted September 27, 2013 Haven't tried this yet but whilst searching for another way around this I found the following will work: shell_exec("(ffmpeg input.avi output.mp4 && php -e 'aphpfile.php') > /dev/null 2> alogfile.log &"); The commands need to be encapsulated in parentheses and turning of stdin ">" and stderr "2>" to output to file also the & at the end will run it in a separate process. So that looks like it has worked perfectly. Wes
SovietRussia Posted September 27, 2013 Posted September 27, 2013 Or just run a mysql_query after the shell_exec code?
wesleyw Posted September 27, 2013 Author Posted September 27, 2013 As the shell_exec would be running in another process they would complete asynchronously so the MySQL statement would change the status of a record before the conversion completes. Wes
SovietRussia Posted September 27, 2013 Posted September 27, 2013 (edited) As the shell_exec would be running in another process they would complete asynchronously so the MySQL statement would change the status of a record before the conversion completes. Wes Sorry, I forgot about that! You could just join the statements? shell_exec([color=#800000]"[color=#333333][font=Verdana]ffmpeg input.avi output.mp4[/font][/color] > page.php 2>&1 &"[/color]); Edited September 27, 2013 by SovietRussia
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now