Why are you using php:// below? If stdin is a file './stdin' will
suffice (or the path instead of ./). If you want to run the PHP script
in stdin you should use one of the following:
include()
include_once()
require()
require_once()
See the manual at php.net for pertinent sections...
> if( ($stdin = fopen( 'php://stdin', 'r' )) === false )
> {
> echo 'Failed to open STDIN'."\n";
> exit();
> }
I seem to remember stream_set_blocking being either experimental or deprecated.
If I remember correctly its for use with the function fsock_open().
> stream_set_blocking( $stdin, false );
>
> $count = 0;
WTF are you thinking? You really need to read the documentation.
Instead of this:
> while( 1 )
> {
> echo 'Foo: '.($count++)."\n";
> if( ($char = fread( $stdin, 1 )) !== false )
> {
> echo $char."\n";
> }
> else
> {
> echo 'Fooo!'."\n";
> }
> }
Try:
<?php
$stdin = fopen("./stdin","r");
while ($stdin AND (!(feof($stdin))))
{ echo fread($stdin,4096); }
?>
Much simpler, correct?
BTW: The infinite loop you have above could be the reason your script is
acting erratically. PHP kills off scripts after they run for so long --
you may just be catching it in different versions of the loop.
Also BTW: I understand what you mean when you say CGI but not CLI
version of PHP, but I really don't think the term CGI applies in this
case. CGI means Common Gateway Interface -- or a way to execute
programs in a special directory designed to keep them from r00ting the
system. In PHP things such as headers are automatic -- no need to type:
print "Content-type: text/html\n\n";
It's a server side scripting language designed to be embedded in things
like web pages and be able to be run without much security concerns.
(i.e. not running a CGI perl scrip as /usr/bin/perl (i.e. not in tainted
mode) -- ouch! and these are the silly things users sometimes do)
-Dan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php