Hi all,

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. 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 the "yes"; then end. So, on 
the screen you will see:

Hello, world!
Hello: yes
yes

However, on one of the servers, it doesn't run like above, 
but in a reversed way: Firstly, it displays nothing but waits 
for your input; you input a "yes", then it displays the "yes", 
then "Hello, world!", then "Hello: yes". So, on the screen it
looks like this:

yes
Hello, world!
Hello: yes

Weird? To me IT IS! I really don't understand why all the 
echos/prints did not function until the script got data from 
tty, even they are before fgets..

I found this issue during an unsuccessfull pear installation. 
The pear installer stopped and waited for my input without 
any prompt - there is prompt message but not displayed!

Can anyone let me know how this can happen? Thanks
in advance!

Alex

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to