• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Output

I have a php page which takes a long time to display (due to amount of different processes).

How could I send output before my script stops ?
(displaying some text telling the user that the first command has just been processed).

Any ideas ? (ob_flush....) ??
Many thanks
0
us111
Asked:
us111
  • 2
  • 2
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
From the PHP Manual.

http://www.php.net/manual

Output Control Functions
The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.

Example 1. Output Control example

<?php

ob_start();
echo "Hello\n";

setcookie ("cookiename", "cookiedata");

ob_end_flush();

?>
 
 


In the above example, the output from echo() would be stored in the output buffer until ob_end_flush() was called. In the mean time, the call to setcookie() successfully stored a cookie without causing an error. (You can not normally send headers to the browser after data has already been sent.)

See also header() and setcookie().

Table of Contents
flush — Flush the output buffer
ob_clean — Clean (erase) the output buffer
ob_end_clean — Clean (erase) the output buffer and turn off output buffering
ob_end_flush — Flush (send) the output buffer and turn off output buffering
ob_flush — Flush (send) the output buffer
ob_get_contents — Return the contents of the output buffer
ob_get_length — Return the length of the output buffer
ob_get_level — Return the nesting level of the output buffering mechanism
ob_gzhandler — ob_start callback function to gzip output buffer
ob_implicit_flush — Turn implicit flush on/off
ob_start — Turn on output buffering


Does this help enough?

Regards,

Richard Quadling.
0
 
Richard QuadlingSenior Software DeverloperCommented:
Something to watch out for though.

If you send "Your request is being processed", you will eventually need to replace this with the results. As you will have already sent headers, you will not be able to send more. But you could send some javascript which loaded a new page with the results, when they where ready.


If your task is taking a LONG time to run, then it may be better off using a seperate server to process these tasks and to not have to worry about the web server holding the page open. The task could update a table which gives the status of the task which the user can then check using a redirect. When the task is finished, the redirect would take them to the output page. Maybe.

0
 
us111Author Commented:
hmm yes, using a database could be a good idea.
I leave this question opened for the moment
0
 
us111Author Commented:
oops sorry forgot this one :=)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now