PHP 执行批处理文件时如何显示加载图像 gif 或消息?

发布于 2024-11-14 13:04:03 字数 400 浏览 2 评论 0原文

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷→糖丶微凉 2024-11-21 13:04:03

我尝试了以下代码,它给了我我想要的东西。该页面在加载 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>

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>
别想她 2024-11-21 13:04:03

您可以使用 AJAX 从另一个网页请求您的 php 文件。然后你让你的 JavaScript 显示一个loading.gif,直到服务器响应请求。

您可以使用 jQuery 来实现此目的: http://api.jquery.com/load/

You can request your php file from another web page using AJAX. Then you have your javascript display a loading.gif until the server answers the request.

You could use jQuery for this: http://api.jquery.com/load/

野の 2024-11-21 13:04:03

您不能仅使用 PHP 来执行此操作,因为它是服务器端执行(页面/脚本在用户可以在浏览器上看到任何内容之前在服务器中呈现)

您应该将脚本放在单独的文件中,然后执行AJAX 调用。

要显示加载图像,请遵循此操作(需要 jQuery 框架)

http://jquery-howto.blogspot.com/2009/04/display-loading-gif-image-while-loading.html

// SHOW YOUR LOADING GIF HERE
$('#result').load('yourscript.php', function() {
 //HIDE YOUR LODAING GIF HERE
});

You can't do this using PHP only since is a server-side execution (the page / scripts are rendered in the server before the user can see anything on his browser)

You should put your script in a separate file, and then do an AJAX call.

To display the loading image follow this (jQuery framework needed)

http://jquery-howto.blogspot.com/2009/04/display-loading-gif-image-while-loading.html

// SHOW YOUR LOADING GIF HERE
$('#result').load('yourscript.php', function() {
 //HIDE YOUR LODAING GIF HERE
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文