-1

I am trying to load header first in my page and then the body content.So i searched on internet,so i came to know about flush function in php.So i tried using it after following an article where it was written about yahoo.That how yahoo uses flush function to render the page by parts.So i used the same technique.But there was no significant improvement,following is my html format which i used after that

<html>
<head>
<title>
</title>
</stylesheet linked></head>
<?php ob_flush();?>
<body>
<header content>

<?php flush();?>

</body>
</html>

But there is no signifcant improvement in page rendering.Please guide me on this code manipulation and how to use flush function to improve performance...

  • You have some examples about how it works in manual: http://php.net/manual/en/function.ob-flush.php – Sal00m Sep 08 '14 at 07:22

1 Answers1

2

you need to start your output-buffer first:

<?php
  ob_start(); //start output buffering here
  //everything from here on is added to the buffer

  echo '<html><body> .. blah blah ... ';
?>

more text or html code here

<?php 
  ob_flush(); //output everything buffered, end output buffering
?>
low_rents
  • 4,161
  • 2
  • 20
  • 47
  • so it means sir.I should replace ob_flush() with ob_start in my code.and flush() with ob_flush() method is it????? – peter joseph Sep 08 '14 at 07:34
  • SO which means first we need to start this with ob_start method – peter joseph Sep 08 '14 at 07:49
  • So if we want to loa d navigation bar first on the page,then we will put ob_start before navigation bar and ob_flush after navigation bar ends.... – peter joseph Sep 08 '14 at 08:25
  • @peterjoseph yes, that would work. but it makes more sense to buffer it all - the whole page for example, imho. – low_rents Sep 08 '14 at 08:37
  • But if we make whole page in buffer.then whole content will load together.right???? – peter joseph Sep 08 '14 at 09:13
  • @peterjoseph yes. also note: if some kind of compression is activated on your server, output buffering might not work. see: http://stackoverflow.com/questions/1862641/compressing-content-with-php-ob-start-vs-apache-deflate-gzip?rq=1 and http://php.net/manual/de/function.ob-gzhandler.php – low_rents Sep 08 '14 at 09:35
  • So it means if gzip compression is enabled in server or in htaccess file.output obuffering wnt work.. – peter joseph Sep 08 '14 at 09:55