Ok, i have a ENDLESS LOOP
i need that loop endless nothing wrong with it! When i start that script via php script.php
it works no problem, but on the second thrid and so on...run it dont works any more proper. I added as test the $output on the second run into the DB to see whats wrong and im getting this error a:1:{i:0;s:24:"sh: 0: command not found";}
its serialized.
Remember the script works on the first run, but never on the 2nd+ run, something is wrong with $output and $video on the 2nd 3rd+ run,
Encoding works in every run also the files get proper renamed, and moved proper
I tried to unset $output
$video
$duration
and $error
at the end of the script, but than i get a error, variables not defined on the 2nd+ run. Any ideas whats wrong?
About the code: I put a snippet not the full code, if typos in there its only copypaste error.
My thinking is something with exec
is wrong, when they give the output to the variable on the 2nd+ run
Here is my script
<?php
while(10) {
// Getting Data From DB
$sql = "SELECT * FROM videos_to_edit WHERE status = 'pending' ORDER BY post_time ASC LIMIT 1";
// Encoding Video;
exec("$mencoder $temp_upload_dir$post_filename -o $temp_upload_dir$r_post_id.mp4 2>&1", $output);
// Checking if Mencoder could encode it
foreach($output as $error) {
if(preg_match('/============ Sorry, this file format is not recognized\/supported =============/', $error)) {
$error1 = "error";
}
}
if(!isset($error1)) {
// Getting duration of Video with mplayer
exec("$mplayer $temp_upload_dir$r_post_id.mp4 2>&1", $video);
// Getting the duration with preg_match
foreach($video as $vidlenght) {
if(preg_match('/ID_LENGTH=/', $vidlenght)) {
$duration = $vidlenght;
$duration = explode("=",$duration);
$duration = $duration['1'];
}
}
// MOVING FILE TO PUBLIC DIR
CODE HERE...
//UPDATING DB
$sql = "UPDATE videos_to_edit SET status = 'finished' WHERE post_id = ?";
}
}
?>
Could it be because you never reset $error1
? If it's ever set here:
$error1 = "error";
it remains set.