[PHP] showing a loading page during search

Associate
Joined
18 Feb 2003
Posts
477
Location
Moscow
I have a function that takes a while to complete and load data into the page what I am trying to do is find a way of while this is going on display another page and then forward onto the correct page rather than have the browser waiting for the page to load.

Another way to describe it would be for example on some sites when you are searching for something a 'Searching' page comes up and then once the search is complete a 'Results' page comes up. Does anyone know if this can be done using PHP with NO Javascript?
 
without javascript your options are very limited.

you could make your program set a 'flag' when the results have been processed . That way you can make a "please wait" page meta refresh every X seconds to check the status of that flag.

Another option would be to use output buffering and flush data to the user as it is processed.
 
Yup, save the results to your database. When the user submits, run the search in the background and redirect the user to a 'searching' page which refreshes every few seconds. On each refresh, check if the search is complete. When it is, redirect the user to their results.
 
Adz said:
Yup, save the results to your database. When the user submits, run the search in the background and redirect the user to a 'searching' page which refreshes every few seconds. On each refresh, check if the search is complete. When it is, redirect the user to their results.

Having thought about it more, that was the next idea I came to. Just trying to plan it out more though I am also looking into the output buffering option also.

Thanks for your help.
 
z3b3dy said:
I am also looking into the output buffering option also.

be careful with outbut buffering - it is very heavy on the server as it requires a constant connection.

i'd recommend using it only if your project is relatively small.
 
jonno.co.uk said:
be careful with outbut buffering - it is very heavy on the server as it requires a constant connection.

i'd recommend using it only if your project is relatively small.

Regarding the load on the server, I have got my system now doing what I want using the following code:
Code:
require "$FILE"; //The loading page image			
ob_flush();
flush();
...
Large SOAP query
...
<meta refresh tag>

This is going to be running on quite a large system but it is only needed on login and for data refresh. Do you think that even this could be a problem?
 
Back
Top Bottom