Php – How to display a loading image gif or message while PHP is executing a batch file

imageloadingphp

I've been searching on the net for the answer, but couldn't find.

How could I show some loading messsage or gif while the long executing script is running. I tested a number of different way like javascript, because my script is trying to use PLINK.exe to tail a file, which take about 30s to return the value. because it's one line code, I can't use flush(), is there any other way I cam make this happen?

<?php
$runCommand  = "C:\wamp\www\TS\batch\plink.exe Sever -l User \"ssh User@Server 'tail -600 /serverlog/test.log'\" ";
$results=system($runCommand);
//exec($runCommand, $results); 
echo $results;
?>

Best Solution

I've tried the following code, which given me exactly what I want. the page is displaying a "loading.gif" while loading the php script, and hide it when the script is finished. This is using JQuery.


//$tr_arname=$_REQUEST['arname'] -> is the variable i've got from previous PHP page.

<body onload="loadingAjax('myDiv');">

<script>
var arname="<?php $tr_arname=$_REQUEST['arname']; echo "$tr_arname"; ?>";
function loadingAjax(div_id)
{
    $("#"+div_id).html('<center><img src="images/loading.gif"><br><br><font color="#006699" face="arial" size="4"><b>Loading arerror.log <br><?php echo "$tr_arname"; ?> <br>Please Wait ...</b></font></center>');
    $.ajax({
        type: "POST",
        url: "ThePHPScriptPage.php",
        data: "arname=" + arname,
        success: function(msg){
            $("#"+div_id).html(msg);
        }
    });
}
</script>

<div id="myDiv"></div>
</body>