Whenever I run a program through an xterm it seems to buffer all of the output (to stdout) until the program is finished. I thought this was just a PHP thing but I wrote similar scripts in C and Perl and they do the same.

Scripts:

PHP
PHP Code:
for($i=0;$i<10;$i++)
{
      echo 
"Hi...\n";
      
flush();
      
sleep(2);

Perl
Code:
for($i=0;$i<10;$i++)
{
     print "Hi...\n";
     sleep(2);
}
C
Code:
#include <stdio.h>

void main()
{
     int i;

     for(i=0;i<10;i++)
     {
          printf("Hi...\n");
          sleep(2);
     }
}
They all do the same thing... I get

Hi...Hi...Hi...Hi...Hi...Hi...Hi...Hi...Hi...Hi...

after 20 seconds.

Maybe I'm just stupid but I could swear I never had this problem when writing QBasic and C programs for DOS years ago...

I have also tried things like this:

./program.php | more
./program.php > output

But the output is still buffered until the end...