STDIN/STDOUT in PHP
| From: | Jimmy Lantz | Date: | Sun, 09 Jun 2002 10:54:18 +0000 |
| Subject: | STDIN/STDOUT in PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-101324@lists.php.net to get a copy of this message | ||
I've been looking for a way to work with stdin/stdout for a mod_rewrite's rewritemap.
There's a working example in Perl, (just returning the input)
#!/usr/bin/perl
$| = 1;
while (<STDIN>) {
print $_;} I've been trying to achieve this with fopen() read and write the php://stdin & php://stdout . #!/usr/local/bin/php -q <?php $fp = fopen("php://stdin", "r"); while (($buf = fgets($fp)) != false) {
$input .= $buf;} fclose($fp); $fp = fopen("php://stdout", "w");
fputs($fp, "$input\n");fclose($fp); ?> But no success. In the apache man they say Avoid one common mistake: never do buffered I/O on stdout! This will cause a deadloop! Hence the ``$|=1'' in the above example Could sommone give some pointers how I could achieve the perl script above in php? TIA Jim.