[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Output

Posted on 2002-06-20
4
Medium Priority
?
252 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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

656 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