I'm trying to get some data from Ajax request when already PHP running a long script ;
but when the Ajax has been answered that script in PHP is completed, and I need to get Ajax response during running other scripts .
JS
setInterval(function(){
$.post( 'progress.php','',
function(data){
$('.-info-').html(data);
});
},100);
progress.php
session_start();
echo $_SESSION['progress'].'%';
running.php
session_start();
$i=0;
while($i<99){
$i++;
$_SESSION['progress'] = $i;
//sleep(1);
//flush();
}
Is there any way to response when "while" is running?
$_SESSIONto disk don't happen till the end of the process. The Session file is anyways locked to the serving process, which means the progress.php process will hang till running.php finishes. You'll have to write the progress to your own file and read from there in progress.php.