Jabop Posted June 3, 2008 Share Posted June 3, 2008 I have a script written that will convert video upon upload. I made it do it in the background to save the user the wait of the conversion process as well. I have two execs(); being called, both of them are crucial parts in the video converting process. However, since the initial conversion process is sent to the background, the second one gets called immediately. Example: exec(do video converting >& /dev/null & disown); exec(update metadata >& /dev/null & disown); This presents a problem: the metadata update execution gets done immediately after the previous process is put into the background, so it tries getting the data from the video that hasn't converted completely just yet. My question is, is there a way I can delay the second execution by a certain amount of time? I tried sleep(x), but that hangs the http request til the sleep is finished as well. Thanks everyone Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 have the second script called by the first. Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 have the second script called by the first. I don't execute an actual php script, but a bash script... Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 I understand. do something like this: make a 3rd script: #!/bin/bash do video converting >& /dev/null; update metadata >& /dev/null then just call the 3rd script, assigning variables as needed in that one. Quote Link to comment Share on other sites More sharing options...
mushroom Posted June 3, 2008 Share Posted June 3, 2008 I tried sleep(x), but that hangs the http request til the sleep is finished as well. I don't think you can avoid that, but you can finish the page. after "</html>" and before sleep(x); add ob_flush(); flush(); Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 I understand. do something like this: make a 3rd script: #!/bin/bash do video converting >& /dev/null; update metadata >& /dev/null then just call the 3rd script, assigning variables as needed in that one. How can I call phpvars into the bash script? I tried sleep(x), but that hangs the http request til the sleep is finished as well. I don't think you can avoid that, but you can finish the page. after "</html>" and before sleep(x); add ob_flush(); flush(); I may give this a shot Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 Double post Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 you pass it like any other bash script <?php $var1 = "var1"; shell_exec("yourscript.sh ".$var1); Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 jonsjava - I'm not familiar with passing any variables to bash actually. There are many that need to be given to the query. So would the 3rd script look something like #!/bin/bash do video converting -i $InputFile -o $OutputFile >& /dev/null; update -i $FinalFile metadata >& /dev/null Etc... ? Forgive me for the monotony. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 looks right. That's how I'd write it. (I'm a linux admin first, php programmer distant 2nd) Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 Well that's good - I just didn't know that I could pass the variables like that. I'll give this a shot when I get the chance and will keep you updated. Thanks for the help Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 just got to thinking. Might be better to merge both of your scripts into one single script, that way, you won't have all that headache. Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 So there is one script now: do video converting -i $InputFile -o $OutputFile >& /dev/null; update -i $FinalFile metadata >& /dev/null I call the script by exec('whatever.sh'.$InputFile,$OutputFile,$Foo);? I know that is failcode, but I don't know how it'd be passed. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 in your script, just have it set so that it reads the variables passed: $var1 = $1; $var2 = $2; $var3 = $3; etc, etc. Seeing how you know bash, you know that $1, $2, $3, etc refers to variables you passed to it in the command line. Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 3, 2008 Author Share Posted June 3, 2008 So when calling the script it is proper to separate variables by commas? exec('script.sh'.$var1,$var2,$var3); Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 3, 2008 Share Posted June 3, 2008 So when calling the script it is proper to separate variables by commas? exec('script.sh'.$var1,$var2,$var3); exec("script.sh $var1 $var2 $var3"); That should work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.