Need help with PHP flush() !

  • danmerrino
  • Novice
  • Novice
  • No Avatar
  • Joined: Aug 13, 2008
  • Posts: 21
  • Status: Offline

Post February 25th, 2009, 6:54 am

hello fellow nerds!

i am afraid to say that i dont have too much experience with php yet and here is my question:

i am trying to use flush() (or ob_flush(), whichever works) to flush the output-buffer in a script that only runs on my local wamp server.

the only thing i want to do is dump information and variables while the script is running, with echo() or print().

the fact of the matter is, that i have not been able to get it to work at all.

is there anybody here that has any experience with outputting the o-buffer while the script is being executed?

are there any special measures i need to take in order to get it to work? like maybe something in php.ini?

i have read most of the stuff on php.net and other sources but to no avail.

any help is desperately appreciated.

greetings,
dan
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 25th, 2009, 6:54 am

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post February 25th, 2009, 3:53 pm

Try the following at the very beginning of the script.
PHP Code: [ Select ]
<?php
 @apache_setenv('no-gzip', 1);
 @ini_set('zlib.output_compression', 0);
 @ini_set('implicit_flush', 1);
 for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
 ob_implicit_flush(1);
   
 // All you need is 256 spaces first
 echo str_repeat(" ", 256)."<pre>"; ob_flush();
 
  1. <?php
  2.  @apache_setenv('no-gzip', 1);
  3.  @ini_set('zlib.output_compression', 0);
  4.  @ini_set('implicit_flush', 1);
  5.  for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
  6.  ob_implicit_flush(1);
  7.    
  8.  // All you need is 256 spaces first
  9.  echo str_repeat(" ", 256)."<pre>"; ob_flush();
  10.  
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • danmerrino
  • Novice
  • Novice
  • No Avatar
  • Joined: Aug 13, 2008
  • Posts: 21
  • Status: Offline

Post February 25th, 2009, 4:57 pm

hello and thanks for your answer.

if i use the code exactly like you told me to i get:

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush.

i tried to modify it like so:

// All you need is 256 spaces first

ob_start();

echo str_repeat(" ", 256)."<pre>"; ob_flush();

then there was no notice anymore but he didnt flush it either.

more ideas are very welcome.

greetings,
dan
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post February 25th, 2009, 5:05 pm

Alright... below is an example code with the flusher that works... try manipulating the code to work like you want it to.
PHP Code: [ Select ]
<?pbp
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);
 
// All you need is 256 spaces first
echo str_repeat(" ", 256)."<pre>"; ob_flush();
$n = 0;
$p = 0;
for($i=0;$i<60;$i++)
{
   for($i=1;$i<57;$i++)
   {
      echo "$i ";
      ob_flush();
      usleep(1);
      ++$n;
   }
   ++$p;
   echo "<strong> ~ $n , $p</strong>\n";
}
?>
  1. <?pbp
  2. @apache_setenv('no-gzip', 1);
  3. @ini_set('zlib.output_compression', 0);
  4. @ini_set('implicit_flush', 1);
  5. for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
  6. ob_implicit_flush(1);
  7.  
  8. // All you need is 256 spaces first
  9. echo str_repeat(" ", 256)."<pre>"; ob_flush();
  10. $n = 0;
  11. $p = 0;
  12. for($i=0;$i<60;$i++)
  13. {
  14.    for($i=1;$i<57;$i++)
  15.    {
  16.       echo "$i ";
  17.       ob_flush();
  18.       usleep(1);
  19.       ++$n;
  20.    }
  21.    ++$p;
  22.    echo "<strong> ~ $n , $p</strong>\n";
  23. }
  24. ?>

I don't know if this would help you at all, maybe if you tell the operating system under which you are trying to run the code on...
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • danmerrino
  • Novice
  • Novice
  • No Avatar
  • Joined: Aug 13, 2008
  • Posts: 21
  • Status: Offline

Post February 25th, 2009, 5:48 pm

well thanks for that.

its windows xp and wamp 2.0 with apache 2.2.11 and php 5.2.8.

now i get all the notices from the loop:

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post February 25th, 2009, 6:02 pm

Well... I don't know what to tell you now... it works perfectly for me... I have no clue what's up with your thing.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • danmerrino
  • Novice
  • Novice
  • No Avatar
  • Joined: Aug 13, 2008
  • Posts: 21
  • Status: Offline

Post February 26th, 2009, 5:44 am

well, thanks for trying!

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: Kurthead+1 and 169 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.