On Thu, 29 Apr 2004 12:05:56 +0200
Jerry <no**@none.com> wrote:
Hi All
How can I produce an output to the browser and let the script
continue to work in the background, producing a later screen output?
Example:
Trigger a database search so that the user immediately sees a
"...searching..." screen while the script actually searches and
later on outputs the result.
I always get a "header already sent" error.
Hi Jerry, see
http://php.net/flush because it sounds like that this is
what you want. flush() will simply flush some output to the webserver
which in turn will flush to the browser at some point which in turn
will display some text to the user.
If you
echo 'searching...';
flush()
sleep(60);
then not necessarily the user will read ``searching...'' because as I
said, the webserver still buffers something and the browser too. So if
you wanna make sure, you need to find out how much you need to output
to make sure that the user will see something. You can just not care
and print some good amount of text to be sure that at least the string
``searching...'' will be displayed.
Now, ``header already sent'' is something else. After you output
anything to the webserver, it creates the headers of the HTTP answer
and will not go back to that step just because you want add a cookie,
a location or something. So, after echo/print/flush anything, do not
use header()/setcookie().