Welcome Guest, Not a member yet? Register   Sign In
Flushing with code ignitor?
#1

[eluser]Unknown[/eluser]
Hi,

I'm wondering how to implement flushing of content with code ignitor.

In previous (non CI) work I've done something along the lines of:

Code:
ob_start("ob_gzhandler");
include 'header.inc.php';
@ob_flush();
flush();
// do some work
include 'footer.inc.php';

In addition to the improved page loading time, it's some time useful when doing long tasks (sending email, complicated DB queries etc.) to:
* output head content
* display a busy image
* flush
* do the the task
* output "task complete" with a bit of javascript that hides the busy image.

Within CI simply trying ob_flush() etc after loading a view simply doesn't work, as CI is using (multiple ?) output buffers behind the scenes (to deal with nested views IINM).

I can do a nasty hack of loading the header view, echoing the output buffer, flushing, emptying the output buffer, then load the main view etc., but:
* This is nasty
* It breaks as soon as output compression is enabled in the config.

Anyone got ideas where I start? I imagine I need to extend the output class and/or write some hooks, but at the moment I'm not sure where to start.

TIA,
Pheet
#2

[eluser]Unknown[/eluser]
I was having the same problem... I want the header of my site to load before the "content" has been processed... as this may take 2-3 seconds... I have the header as it's own view... eg.

Code:
$this->load->view('includes/header');
    $this->load->view($content);
    $this->load->view('includes/footer');

Where $content will be the name of the view that determines the content...

Even with seperate views, and adding tons of ob_start(), ob_flush(), flush(), etc. in a bunch of different places in the code, nothing shows until the entire content of all called views have been processed...

This makes it so when you click a link on one page, nothing happens for 2-3 seconds, then the new page loads all at once...

I need the header to load immediately, followed a few seconds later by the rest of the content... this way, people will know they actually clicked a link, and they can use the site navigation while waiting if they wanted to go to a different site.

I've searched the forums and can't figure out a proper way to flush to buffer... is it possible? We're in the R&D stage, and if this can't be done we're going to have to rethink the architecture of our site completely.
#3

[eluser]summery[/eluser]
Hola. I'd also like to be able to flush the output buffers early, but the forums and google seem to be mysteriously silent. If you have an implementation, please post it! Thanks, ~S
#4

[eluser]InsiteFX[/eluser]
Try placing the ob_start(); at the top of your controller.

Enjoy
InsiteFX
#5

[eluser]billmce[/eluser]
That worked for my problem!
thanks.
#6

[eluser]Nekluh[/eluser]
Have this stopped working, or am I doing it wrong?

I begin with
ob_start();

then making this every loop:
ob_flush();
flush();

But everything renders at the same time anyway
#7

[eluser]WanWizard[/eluser]
In CI all output goes through the Output class, which buffers all output. If you use ob_start(), you'll just add another level of buffering, and flush() will actually flush into the buffer managed by the Output class.

Also, output is buffered when you have compression enabled. If you have this enabled in the PHP config, the output is even buffered without using ob_start() or the output class... You can test that by echo'ing some text out in a loop, with a delay between the echo's. CI doesn't buffer echo's, so if the output still appears all at once, output is being buffered elsewhere.
#8

[eluser]Nekluh[/eluser]
Ok thanks.

It started working as I skipped ob_start()
#9

[eluser]Tybion[/eluser]
The above did not work for me with CI 2.1.0, exactly, but this did ..

First thing in the Controller method, call ob_start() ..
Code:
public function report($page) {
    ob_start();   // create a top output buffer

In the View file, the following gets the content to the browser ..
Code:
//Once I have 200 rows to display, give the user something to look at, while waiting for the rest ..
  if ($count==200) {
    ob_end_flush(); // php.net:'send the contents of the topmost output buffer and turn this output buffer off'
    ob_flush();     // for an unknown reason, need another flush
  }

If you understand why this works, can you please add an explanation to this article.
#10

[eluser]Tybion[/eluser]
Another way that works in CI 2.1.0 is to do as above in the controller, and then near the top of the View have only these 2 lines ..

Code:
ob_end_flush();  // flush and turn off my outer output buffer
ob_end_flush();  // turns off the inner CI output buffer?

Yet another way in the View (using the same controller) is ..

Code:
ob_end_flush();  // flush and turn off my outer output buffer
//   :    :
// in a loop flush the inner CI buffer every 200 rows
  if ($count % 200 == 0) {
    ob_flush();
  }





Theme © iAndrew 2016 - Forum software by © MyBB