Jquery自动刷新10秒后停止刷新

时间:2016-02-11 03:57:16

标签: javascript php jquery ffmpeg

我有这个JQuery脚本在上传视频后每隔2秒自动刷新一次,并使用ffmpeg检索处理视频所需的估计时间

然而,我的刷新脚本在10-15秒后停止刷新。当我删除此session_start()时,我将问题追溯到 session_start(); ;我的刷新脚本工作得很好。这可能是什么原因和解决方案?

videoupload.php

<div id="myDiv" name="myDiv" title="test">
        <h5>Encoding percentage</h5>
        <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
                <script>
                $("#Submit").click(function(event){
                setInterval(function(){
                $("#myDiv").load('progress.php')
                }, 2000);
                });
                </script>
        </div>

Progress.php

<?php

$content = @file_get_contents('logfile.txt');

            if($content){
            //get duration of source
            preg_match("/Duration: (.*?), start:/", $content, $matches);

            $rawDuration = $matches[1];

            //rawDuration is in 00:00:00.00 format. This converts it to seconds.
            $ar = array_reverse(explode(":", $rawDuration));
            $duration = floatval($ar[0]);
            if (!empty($ar[1])) $duration += intval($ar[1]) * 60 ;
            if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60 * 60;

            //get the time in the file that is already encoded
            preg_match_all("/time=(.*?) bitrate/", $content, $matches);

            $rawTime = array_pop($matches);

            //this is needed if there is more than one match
            if (is_array($rawTime)){$rawTime = array_pop($rawTime);}

            //rawTime is in 00:00:00.00 format. This converts it to seconds.
            $ar = array_reverse(explode(":", $rawTime));
            $time = floatval($ar[0]);
            if (!empty($ar[1])) $time += intval($ar[1]) * 60;
            if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;

            //calculate the progress
            $progress = round(($time/$duration) * 100);

            echo "Duration: " . $duration . "<br>";
            echo "Current Time: " . $time . "<br>";
            echo "Progress: " . $progress . "%";

}

?>

upload.php的

session_start();

$userID = $_SESSION['login_user'];
// rest of the code to convert video using ffmpeg

0 个答案:

没有答案