Solved

Output

Posted on 2002-06-20
4
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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