Solved

Output

Posted on 2002-06-20
4
234 Views
Last Modified: 2006-11-17
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
Comment
Question by:us111
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
RQuadling earned 50 total points
ID: 7106802
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
 
LVL 40

Expert Comment

by:RQuadling
ID: 7106811
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
 
LVL 8

Author Comment

by:us111
ID: 7111182
hmm yes, using a database could be a good idea.
I leave this question opened for the moment
0
 
LVL 8

Author Comment

by:us111
ID: 7536524
oops sorry forgot this one :=)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now