Endless loop problem $var gets not set or dont gets updated
I call that script via HTTP, will later done with php-cli. First video encoding i get the correct duration, and right data is entered in the db, but when script gets the second video all works, only the duration is wrong, gets the data from last insert, if i unset the vars i get this error
PHP Notice: Undefined variable: duration
and i know this is an endless loop, i have also a sleep command in the script so that the db dont gets called all the time. How i can get it get working that $duration gets the real value. First process its working, second all works besides duration.
Right now im working on windows LAMP, didnt test yet the script on centos
while(10) {
// GET DATA FROM DB
// CHECK STATUS
if($check == true) {
exec("$mencoder $temp_upload_dir$post_filename -o $temp_upload_dir$r_post_id.mp4 2>&1", $output);
foreach($output as $error) {
if(preg_match('/============ Sorry, this file format is not recognized\/supported =============/', $error)) {
$error1 = "error";
break;
}
}
if(!isset($error1)) {
exec("$mp4box 开发者_如何学C$temp_upload_dir$r_post_id.mp4");
exec($mplayer . " " . $temp_upload_dir . $r_post_id . ".mp4 2>&1", $video);
foreach($video as $vidlenght) {
if(preg_match('/ID_LENGTH=/', $vidlenght)) {
$duration = $vidlenght;
$duration = explode("=",$duration);
$duration = $duration['1'];
break;
}
}
// MOVE FILES
// UPDATE DB
}
}
When you do
while(10)
what you are telling the program is
while(10==10)
While is looking for a boolean value ie (true or false). Since 10 will equal 10 and always will equal 10, this statement is ALWAYS true. The only way to exit is to:
break;
You only have breaks in your foreach loops. Therefore you have nothing to break out of your while loop. As for why your variables aren't being set properly, it looks like you are simply breaking out of the foreach loops too soon before they finish looping through the videos.
精彩评论