<!--------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>';
I have an issue with codeigniter. i have tried to call 2 functions simultaneously using ajax but no luck, Problem is when i do call my 1st function , 2nd function will be always pending until the first function completes the process.
so any suggestions?
my current code as follows.
So basically what i'm trying to do is when i call testp() function it will load the view with progress bar then by move() js function will call convo() function via ajax to start the conversion process and update the 123.txt file then within the move() js function i will be calling another ajax call to retrieve current conversion progress from 123.txt file(testprogress()). and i have set interval within the frame function in order to get current progress from 123.txt file. but the issue is as i mentioned earlier even though i call testprogress() function it won't run until convo() function finishes it's process. which makes my progress bar getting updated 100% at once.
and also please note if i used just php without using codeigniter it works perfectly.