From: Marten Lehmann on
Hello,

> daniel(a)daniel-laptop:~$ php test.php> /dev/null
> Error 1
> Error 2
> daniel(a)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);
?>

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.

Can the STDERR constands be enable somehow at compile-time for php-cgi?

Regards
Marten
From: Daniel Egeberg on
On Wed, Mar 24, 2010 at 14:12, Marten Lehmann <lehmann(a)cnm.de> wrote:
> Hello,
>
>> daniel(a)daniel-laptop:~$ php test.php>  /dev/null
>> Error 1
>> Error 2
>> daniel(a)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);
> ?>
>
> 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.
>
> Can the STDERR constands be enable somehow at compile-time for php-cgi?
>
> Regards
> Marten

You can see how the CLI SAPI differs from the other SAPIs here:
http://php.net/manual/en/features.commandline.differences.php

--
Daniel Egeberg
From: "Jan G.B." on
2010/3/24 Marten Lehmann <lehmann(a)cnm.de>

> Hello,
>
>
> daniel(a)daniel-laptop:~$ php test.php> /dev/null
>> Error 1
>> Error 2
>> daniel(a)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
>
>