PHP 执行批处理文件时如何显示加载图像 gif 或消息?
我一直在网上寻找答案,但找不到。
当长时间执行的脚本运行时,如何显示一些加载消息或 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我尝试了以下代码,它给了我我想要的东西。该页面在加载 php 脚本时显示“loading.gif”,并在脚本完成后隐藏它。这是使用 JQuery。
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.
您可以使用 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/
您不能仅使用 PHP 来执行此操作,因为它是服务器端执行(页面/脚本在用户可以在浏览器上看到任何内容之前在服务器中呈现)
您应该将脚本放在单独的文件中,然后执行AJAX 调用。
要显示加载图像,请遵循此操作(需要 jQuery 框架)
http://jquery-howto.blogspot.com/2009/04/display-loading-gif-image-while-loading.html
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