如何在PHP执行批处理文件时显示加载图像gif或消息? [英] How to display a loading image gif or message while PHP is executing a batch file?

查看:94
本文介绍了如何在PHP执行批处理文件时显示加载图像gif或消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在网上搜索答案,但找不到。

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

如果长时间执行脚本,我怎么能显示一些加载消息或gif在跑。我测试了许多不同的方式,如javascript,因为我的脚本试图使用PLINK.exe来拖尾文件,这需要大约30秒来返回值。因为它是一行代码,我不能使用flush(),有没有其他方法可以实现这一点?

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;
?>


推荐答案

我尝试过以下代码,这给了我我想要的东西。页面在加载php脚本时显示loading.gif,并在脚本完成时隐藏它。这是使用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>

这篇关于如何在PHP执行批处理文件时显示加载图像gif或消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆