tags:

views:

53

answers:

1

Hello, I would like to monitor my program which is running on the web server. Can I draw the progress bar or simply show the percentage which is returned by my code? The php script is spawning the external code with parameters.

 $Status="rendering...";
 $cmd = "cd $rpath && $envopts /home/arm2arm/bin/sph2grid";
 $shellcmd=$cmd.$params.'| tee  sph2grid.log ';
 echo '<strong>'.$shellcmd.'</strong>';
 $tmp=shell_exec($shellcmd);

then after all I am showing the log file:

 <?php
 function ViewLog() {
 $string = file_get_contents('../../PHP-Login/tmp/sph2grid.log');
 $string = str_replace("\n", '<br>', $string);
 echo $string;
 }    
 ?>

Can I bind the output of my application to some "<div>"?

Thanks in advance.

Arman.

+3  A: 

U can use javascript to setup a timer interval that spawns ajax processes to poll a php page where the percentage is being output. you can then grab the response of that page and append it to a div:

setInterval (pollPage, 1000);
function pollPage()
{
   $.get("percentageComplete.php",output);
}

function output(data)
{
    $("#yourDiv").empty().append(data);

}

in percentageComplete.php you need to get the percentage completed of the calculations

Luis
unfortunately the hardest part here is what you put in the percentageComplete.php file
Ty W
well, that depends on what is being logged. The php file can parse the log and get that info.
Luis
@Luis: Thanks for the solution. are there way to stop the timer? Should I put the timer to infinity to stop it?
Arman
First store the reference to yout timeout on a variablevar t=setInterval (pollPage, 1000);to stop it:clearTimeout(t);
Luis
Nice!! Thank you.
Arman