Re: constants STDOUT, STDERR, STDIN not working in 5.2.x?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/3/24 Marten Lehmann <lehmann@xxxxxx>

> Hello,
>
>
>  daniel@daniel-laptop:~$ php test.php>  /dev/null
>> Error 1
>> Error 2
>> daniel@daniel-laptop:~$ ./src/php-5.2.12/sapi/cli/php test.php>
>>  /dev/null
>> Error 1
>> Error 2
>>
>
> well, using php-cli instead of php-cgi, this finally worked:
>
> <?
> fwrite(STDERR, "test\n");
> fclose(STDERR);
> ?>
>
>
Weird, this does not work with the Ubuntu Version I'm using.
As reported in my previous email, I only can print out to STDERR when I
properly use php://stderr with fopen() - no matter if I use read or write
mode in fopen(). So be cautious when developing for different systems. Here
are some examples:

*** WORKS:
$ php
<?php $x = fopen('php://stderr', 'w'); fwrite($x, 'Foo'); fclose($x); ?>
Foo

*** FAILURE:
##############
$ php
<?
fwrite(STDERR, "test");
?>
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/user/- on line 2

###############
$ php
<?php $x = fopen('php://stderr', 'w'); fwrite($x, 'Foo');
fwrite(STDERR, 'Bar');
fclose($x); ?>
Foo
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/user/- on line 2

###############
$ php
<?php $x = fopen(STDERR, 'w'); fwrite($x, 'Foo'); fclose($x); ?>
// Nothing happens, no warning, no error and no "Foo"




But why doesn't it work with php-cgi? That's a binary that is called with
> the php-file is parameter the same way as php-cli. So both come with
> STDIN/STDOUT/STDERR contrary to scripts running through mod_php.
>
> What is the real difference between php-cli and php-cgi? This
> "fclose(STDERR);" is really important for one customer, because this is
> seems to be the only way to suppress later output to STDERR in the same
> script by external commands and functions that are too hard to change. But I
> don't want to break things for all other customers just to make one happier.
>

Well, see this..
$ php
<? var_dump(STDERR); ?>
string(6) "STDERR"

:-(


> Can the STDERR constands be enable somehow at compile-time for php-cgi?
>
> Regards
> Marten
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux