PDA

View Full Version : Very weird php behavior on WH server...



stonix
07-20-2004, 03:31 PM
Please take a look at following very simple script;

#!/usr/bin/php -q
<?
echo "Hello, world!\n";
if (!$tty) {
$tty = fopen('php://stdin', 'r');
}
print "Hello: ";
$ch = fgets($tty, 1024);
print "$ch\n";
?>

I tested it on many servers other that WH's. Here is how it running (you can figure out yourself): Firstly it displays "Hello, world!", then displays "Hello: " at second line and waits for user input, you input a "yes" and it displays a "yes", end. So on the screen you will see:
Hello, world!
Hello: yes
yes

However, on the WH server, it is like this: Firstly, it displays nothing but waits for your input; you input a "yes", then it displays a "yes", then "Hello, world!", then "Hello: yes". So on the screen it's like this:
yes
Hello, world!
Hello: yes

Weird? To me it IS! I really don't understand why all the echo/print did not function until it get data from tty, even they are before fgets?

I found this issue when install pear... The reason pear installer stopped is that it was waiting for my input without any prompt:)

Can anyone let me know how this can happen?

Alex

stonix
07-20-2004, 05:23 PM
OK, the issue resovled:)
Just turned off the output_buffering in php.ini then it worked the correct way.

Alex