0

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

RogerLawrence
  • 135
  • 1
  • 2
  • 9
  • This should be of some help: http://stackoverflow.com/questions/30005/how-do-i-fire-an-event-when-a-iframe-has-finished-loading-in-jquery – th3mus1cman Feb 24 '12 at 21:50
  • you gotta use jQuery I believe – Grigor Feb 24 '12 at 21:51
  • I have tried:
    Then adding some javascript...
    – RogerLawrence Feb 24 '12 at 22:14
  • For some reason can't hit enter while adding a comment? – RogerLawrence Feb 24 '12 at 22:18

3 Answers3

2

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

echo "Loading";
flush();

sleep(10); // Simulate long process time
echo "Finished";
Mike B
  • 31,886
  • 13
  • 87
  • 111
0

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.

  • So to be clear, the iframe would go to status.html for instance. This file would contain the status bar and the checks and x's table. The java script would call the php file for the necessary variables? – RogerLawrence Feb 24 '12 at 23:04
  • After the frame is fully loaded with the animated gif, the javascript calls the php page using an AJAX call and when the call returns, puts the return value into the body of the frame. – Konstantin Tarashchanskiy Feb 24 '12 at 23:19
0

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.

RogerLawrence
  • 135
  • 1
  • 2
  • 9