<!--------TEST CONTROLLER-------------->
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class test extends CI_Controller{
public function testp()
{
$this->load->view('admin/user/test');
}
public function convo()
{
$this->ConverterOperationsHandler->convo();
}
public function testprogress()
{
$this->ConverterOperationsHandler->testprogress();
}
public function tests()
{
$tet='a1a67b265388c6d19d4b62e5b1da6740de0bf055';
$tet2='18';
$tet3='3';
$this->ConverterOperationsHandler->downloadFileRequiredMp3($tet,$tet2,$tet3);
}
}
<!--------------------MODEL----------------------------->
public function convo()
{
$arrDownloadInfo['url'] = 'https://www.youtube.com/watch?v=cg3myULHqiE';
$arrDownloadInfo['format_id'] = '249';
$arrDownloadInfo['Filename'] = 'test123456';
$quality = '128';
$cmd = 'C:/Users/Ganeendra/Desktop/youtube/ffmpeg.exe'.' -i '.'assets/temp/'.$arrDownloadInfo['Filename'].'.webm -vol '.'2560'.' -y -acodec libmp3lame -ab '.$quality.'k '.'assets/downloads/convo_123.mp3' . ' 2> assets/logs/' . '123' . '.txt';
exec($cmd);
exit(json_encode('true'));
}
<!------------------------------------------------>
public function testprogress()
{
$content = @file_get_contents('assets/logs/123.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;
exit(json_encode($progress));
}
}
<!---------------VIEW----------------------->
echo '<style> #myProgress {
width: 100%;
background-color: grey;
}
#myBar {
width: 1%;
height: 30px;
background-color: green;
} </style>';
echo '<div id="myProgress">
<div id="myBar">1%</div>
</div>';
echo'<script src="http://localhost/search/assets/js/jquery-3.2.1.min.js"></script>';
echo '<script type="text/javascript"> move();
function move() {
$.getJSON("http://localhost/search/test/convo",function(data){});
var elem = document.getElementById("myBar");
var width = 1;
var id = setInterval(frame, 10);
function frame() {
$.getJSON("http://localhost/search/test/testprogress",function(results){
width=results;
if (width > 100) {
clearInterval(id);
}
else if(width==100)
{
elem.style.width = width + "%";
elem.innerHTML = width * 1 + "%";
}
else
{
width++;
elem.style.width = width + "%";
elem.innerHTML = width * 1 + "%";
}
});
}
}
</script>';
我的codeigniter有问题。我试图使用ajax同时调用2个函数,但是没有运气,问题是当我确实调用第一个函数时,第二个函数将一直挂起,直到第一个函数完成该过程。
有什么建议吗?
我当前的代码如下。
所以基本上我想做的是,当我调用testp()函数时,它将加载进度条视图,然后通过move()js函数将通过ajax调用convo()函数以开始转换过程并更新123.txt文件,然后在move()js函数中,我将调用另一个ajax调用,以从123.txt文件(testprogress())检索当前的转换进度。我已经设置了帧功能内的间隔,以便从123.txt文件中获取当前进度。但是问题是正如我前面提到的,即使我调用了testprogress()函数,它也不会运行,直到convo()函数完成该过程为止。这使我的进度栏立即获得100%的更新。
,并且还请注意,如果我仅使用php而不使用codeigniter,则效果很好。