My idea is to display the current details of the procedure to the user and immediately refresh the page which will start on the next batch. This will happen over and over again until the queue for the procedure is empty. It doesn't work. After the first refresh the session variable is blanked out.
My question is either, why doesn't my idea work or what is a better way of accomplishing my goal?
Here is a look at my code, I took all of the details out and tried just to leave the logic behind.
Code: Select all
function displayPage(){
//check if the user has filled out the start procedure form
if(isset($_POST['formData'])){
$this->_processFormData();
unset($_POST['formData']);
}
//check if a start procedure form has been processed yet
if(isset($_SESSION['sessionData'])){
//the form has been filled out and processed, so display
//current procedure results to the user
$this->displaySessionDataProcessingTable();
$this->refreshRate = 1; //1 second until next page refresh
}else{
//the form has not been filled out or processed yet, so display
//the form to the user
$this->displayCollectUserDataTable();
}
}
function displayCollectUserDataTable(){
//code here will create a form to collect data from the user
//post the form data to $_POST['formData']
return $formHTML;
}
function _processFormData(){
require_once('myOwnClass.php');
$anObject = new myOwnClass();
$anObject->prepareForLargeProcedure($_POST['formElementX'], $_POST['formElementY']);
$_SESSION['sessionData'] = $anObject;
}
function displaySessionDataProcessingTable(){
require_once('myOwnClass.php');
$tempObject = $_SESSION['sessionData'];
$totalComplete = $tempObject->completed;
$leftOnQueue = $tempObject->queue;
if($tempObject->error){
$status = "Internal Error";
unset($_SESSION['sessionData']);
$this->refreshRate = 1200; //turn off the refresh by setting it to 20 minutes
}elseif($tempObject->complete){
$status = 'Complete';
unset($_SESSION['sessionData']);
}elseif(!$tempObject->start){
//this is the first run, so lets just display this page and get to work
$tempObject->start = true;
$status = 'Working';
$_SESSION['sessionData'] = $tempObject;
}else{
$status = 'Working';
//code here will create a batch $nextBatch
//now lets send out the batch to be processed (this takes about 20 to 30 seconds)
$tempObject->workOnBatch($nextBatch);
$_SESSION['sessionData'] = $tempObject;
if($lastBatch){
$this->refreshRate = 1200; //turn off the refresh by setting it to 20 minutes
}
}
//code here will create the html to display the statistics of the process
return $returnHTML;
}