So I have a form that the user fills out, when submitted an new tab opens to load the results - the script iterates through multiple XML files - this can be a time consuming process since a lot is happening in that script (2-10 minutes). I wanted some AJAX that would track the progress of the results page so what I did was I had the results page update the user's session (You may just want to skip to the bottom for my question) Example:
$_SESSION['fileCount'] = $fileCount;
for($i=0;$i<fileCount;$i++){//iterate through xmls
$_SESSION['curFile'] = $xml[...];
$_SESSION['curCount'] = $i;
//Do stuff
}
The form tag on the parent page looks like:
<form action="results/" method="post" onsubmit="openProgressDialog()" target="_blank">
the function above looks like:
function openProgressDialog(user){
$('#loadSplash').dialog('open');
var loading = true;
var sleep = 50;
var precent = 0;
var fileCount = 0;
var i = 0;
var curFile = '';
while(loading){
$.getJSON('php/getProgress.php?u='+user, function(data) {
var items = [];
$.each(data, function(key, val) {
if(key == 'fileCount')
fileCount = val;
else if(key == 'curCount')
i = val;
else if(key == 'curFile')
curFile = val;
});
if(fileCount > 0){
//Do stuff
$('#pregressbar').progressbar('value',(i/fileCount)*100);
if(i == fileCount){
sleep = 0;
loading = false;
}
}
}).delay(sleep);
}
}
And finally the the getProgress.php looks like:
<?php
session_start();
$progress =array('fileCount' =>intval($_SESSION['fileCount']),'curCount' =>intval($_SESSION['curCount']),'curFile'=>$_SESSION['curFile']);
echo json_encode($progress);
?>
So I know I just used an odd combo of pseudo and real code and I'm also aware that the JS function is incomplete - I've been monitoring the NET panel in firebug to verify functionality.
So my issue is that the getProgress.php doesn't return until the results/index.php page completes - which complete defeats the purpose of all this. Is there something about multiple php scripts executing or using the same resources simultaneously that is my hold up here?
I'm running a new version of apache/php on LAMP/Ubuntu.
As a side note/question I'm particularly interested by this topics because I'm planning a multiplayer game that uses AJAX/php/mySQL/long polling and I'm curious if there is anything I should be aware of venturing into that project.