Hi all
I'm using a $.messager.progress to monitorize a php long-script task at server side.
This is done by mean of making calls to server and retrieve progres status stored in $_SESSION variables
Here comes the relevant client side code:
// open messager window
$.messager.progress({
title: 'Restore',
msg: 'Restoring database',
interval: 0 // do not perform auto update.
});
// perform call to long time consuming php server side task ( restore database contents with provided file )
$.ajax({
type:'POST', // use post to send file
url:"/agility/server/adminFunctions.php",
dataType:'json',
data: {
Operation: 'restore',
Data: $('#tools-restoreData').val()
},
contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
success: function(data) {
if (data.errorMsg){
$.messager.show({ width:300, height:150, title: 'Database Restore Error', msg: data.errorMsg });
} else {
$.messager.alert("Restore Database","Base restore success<br />Please reinit application","info");
}
$.messager.progress('close');
},
error: function(XMLHttpRequest,textStatus,errorThrown) {
$.messager.alert("DBRestore Error","Error: "+textStatus + " "+ errorThrown,'error' );
$.messager.progress('close');
}
});
// function to monitorize database restore progress info
function getProgress(){
$.ajax({
url:"/agility/server/adminFunctions.php",
dataType:'json',
data: {
Operation: 'progress'
},
success: function(data) {
if( data.progress !== "Done" ){
var bar = $.messager.progress('bar'); // get the progressbar object
bar.progressbar('setValue', data.progress); // set new progress value
setTimeout(getProgress,200); // reload progress status in 200 msecs
} else {
$.messager.progress('close');
}
}
});
}
// start monitoring database restore progress info
setTimeout(getProgress,200);
At server side there are "standard" session status handling:
.....
if ($operation==="progress") {
// retrieve session status and return
session_start();
$sid="0";
if (isset($_SESSION["progress"])) $sid=$_SESSION["progress"];
echo json_encode( array( 'progress' => strval($sid) ) );
return;
}
....
// called several times from long time consuming php process
function setSessionProgressStatus($str) {
session_start(); // if session is already started this call is ignored
$_SESSION["progress"]=$str;
session_write_close(); // flush and unlock session vars to allow another process to access them
}
....
I't works fine.... in Linux and Mac.
When trying to use it in Windows 7 (either Fireforx or Chrome) only one ajax call is submitted to monitorize progress, Thus only last "Done" report is received
I'm unsure but think that long script blocks server, so progress monitor calls are ignored until main task ends, thus the one and only message received is last one
Is it true, or there are something wrong in my client-side code?
Thanks in advance
Juan Antonio