Solved

Output

Posted on 2002-06-20
4
241 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:
Richard Quadling 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:Richard Quadling
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 look for a specific file type in a local or remote server directory using PHP.

820 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