dsfsdf7852
2011-06-09 12:42
浏览 77
已采纳

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

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

图片转代码服务由CSDN问答提供 功能建议

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

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

 &lt;?php 
 $ runCommand =“  C:\ wamp \ www \ TS \ batch \ plink.exe服务器-l用户\“ssh用户@服务器'tail -600 /serverlog/test.log'\”“; 
 $ results = system($ runCommand);  
 // exec($ runCommand,$ results);  
echo $ results; 
?&gt; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douwu5009 2011-06-13 05:58
    已采纳

    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>
    
    点赞 打赏 评论
  • dongquan6030 2011-06-09 12:45

    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/

    点赞 打赏 评论
  • duanpu2272 2011-06-09 12:51

    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
    });
    
    点赞 打赏 评论

相关推荐 更多相似问题