10

In my website(running with drupal) the ob_flush function takes a long time(between 10 - 100 secs) to be executed. How do I find out why? What can cause this so long time? enter image description here

rineez
  • 753
  • 13
  • 33
user16948
  • 4,801
  • 10
  • 30
  • 41
  • What makes you think this function freezes up your application? – ualinker Dec 16 '12 at 17:59
  • @ualinker Please see the image I just uploaded – user16948 Dec 16 '12 at 18:03
  • Can you please also paste code with `ob_start()` and `ob_flush()` context? – ualinker Dec 16 '12 at 18:05
  • look to the functions listed by ob_list_handlers() – goat Dec 16 '12 at 18:10
  • @rambocoder `ob_list_handlers()` returns an array with 2 values: "default output handler" – user16948 Dec 16 '12 at 18:21
  • have you tried to increase buffer size? option **output_buffering** in php.ini file – Gediminas Mar 22 '13 at 04:33
  • I hope this thread has not become a zombie yet. I see that you are talking about core drupal code here. Our drupal 7 site also is occasionally experiencing similar problem with ob_flush and interestingly inside drupal_page_footer() itself. Have you been able to get to the root of this issue? It would be great if you could share what you learned. – rineez Jul 20 '18 at 12:39

4 Answers4

2

Try this:

ob_start();
//Your code to generate the output
$result = ob_get_contents(); //save the contents of output buffer to a string
ob_end_clean();
echo $result;

It is run quick for me.

1

[You may want to tag your question with Drupal, since this feels like it might be a Drupal issue. Specifically, I suspect that when you flush the buffer, you're writing to an outer buffer, which triggers a ton of hooks to be called to filter the data you've just written.]

I suspect that your problem is nested buffers. Drupal really likes buffers and buffers everything all over the place. Check the result of:

echo "<pre>\nBuffering level: ";
    . ob_get_level() .
    . "\nBuffer status:\n"
    . var_dump(ob_get_status(TRUE))
    . "\n</pre>";

If you've got nested buffers, then I suspect ob_flush() will do nothing for you: it just appends the contents of your inner buffer into the next outermost layer of buffering.

Nested buffers can come from Drupal itself (which the above will show), or from the settings for zlib-output-compression and output_buffering (try twiddling those, see if it changes anything).

If your buffers are not nested, and the above settings do not help, then you may also want to split the operation into pieces, and run the profiler there, to see which part is taking the time:

$data = ob_get_contents(); // Return the contents of the output buffer.
ob_clean(); // Clean (erase) the output buffer.
ob_end(); // Close the buffer.
echo($data); // Output our data - only works if there's no outer buffer!
ob_start(); // Start our buffer again.

The question then becomes, though, "what are you trying to accomplish?" What do you think ob_flush() is doing here? Because if the answer is "I want to push everything I've done so far to the browser"... then I'm afraid that ob_flush() just isn't the right way.

Dewi Morgan
  • 1,143
  • 20
  • 31
-1

SET

output_buffering = Off

in php.ini

-2

use

<?ob_start();?>

at the beginning of the page and

 <?ob_flush();?>

at the end of the page, to solve this problem.

lalith222
  • 309
  • 5
  • 16