How to display page before the script is over?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
donald128
Forum Newbie
Posts: 2
Joined: Thu Aug 13, 2009 7:28 am

How to display page before the script is over?

Post by donald128 »

Hey!

My script consists of two parts.
The first part generates HTML page.
The second part loads a resourse from the net and saves it into a file.
Loading is a long operation and can take up to 10 seconds.
The first and the second parts are completely indepenent (loading has no impact on the look of the page).

At the end of the first part I call flush(), that makes page displayed instantly.

However, embedded SWF movie is not displayed at this moment.

SWF is the key element of the page and it must be displayed as fast as possible.
It is embedded in the page with SwfObject library.
And the problem is that SwfObject starts to open SWF on "onLoad" event of the page.

But "onLoad" event comes at the end of the _second_ part.
That is "onLoad" can occure in 10 seconds.
So in spite flush() call the user has to wait for 10 seconds in vain.

Is it possible to solve the task on PHP side?
Is it possible to run "loading" task (the second part) in a separate process?
Is it possible to tell the browser before the second part starts, that the page is reay and you can broadcast the "onLoad" event.

Thanks for reading this very long story.
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: How to display page before the script is over?

Post by robnet »

Rather than using the onload event at the end of your page you could put the code in <script> tags before your flush().
So, if your code is currently 'onload='mycode()' - Add the following before flush(), but after the element it requires has been loaded:

Code: Select all

<script type="text/javascript">
 mycode();
</script>
 
donald128
Forum Newbie
Posts: 2
Joined: Thu Aug 13, 2009 7:28 am

Re: How to display page before the script is over?

Post by donald128 »

Thanks, robnet!
I have already found a good way to solve the problem.
I've put my SWF inside iframe.
Post Reply