While loading PHP script, display animated GIF

给你一囗甜甜゛ 提交于 2019-12-11 18:29:56

问题


I have tried to get several examples that I have found on here and the internet with out success.

Goal: To display a animated gif while php scripts run.

Background: This page is loaded via iframe. The php script I have tests 3 vpn connections and then displays a check (good) or an X (bad). The php portion works, but since there is a delay while testing I want to display the animated gif progress bar.

Running Apache on CentOS 5.7

Currently this is done in a single file named: status.php

I thank you in advance for any assistance.

Roger


回答1:


You can flush the buffer to the browser while PHP is still processing.

echo "Loading";
flush();

sleep(10); // Simulate long process time
echo "Finished";



回答2:


The trick to doing it is not to actually open the PHP file in the iframe. Yeah, seems count intuitive, doesn't it?

Your iFrame should be a page that contains the animated gif and some javascript that will make a call to the php server, get the results, and change the animated gif to the results of the script.




回答3:


Resolved the challenge:

1) Added this to status.php

http://pastebin.com/KR1zPezG

So the iframe loads status.php --> shows the gif --> Loads status2.php --> displays results

NOTE: the pastbin contents are pretty much the whole status.php file, other than the html /html tags.



来源:https://stackoverflow.com/questions/9438535/while-loading-php-script-display-animated-gif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!