ID:               22839
 Updated by:       [EMAIL PROTECTED]
 Reported By:      gk at proliberty dot com
-Status:           Open
+Status:           Assigned
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5CVS, 4CVS (2007-07-13)
-Assigned To:      
+Assigned To:      jani
 New Comment:

I have created a patch to improve this situation a bit:

http://pecl.php.net/~jani/patches/errors_to_stderr.patch

Might need some tuning but this should work.
I overloaded the display_errors php.ini directive,
it allows using 'stderr' as parameter which makes all error messages
output in CLI/CGI to go to STDERR.

Works fine in *nix, I haven't tested in Windows..


Previous Comments:
------------------------------------------------------------------------

[2007-06-29 20:13:58] gk at proliberty dot com

This is not about where  errors be LOGGED, but about what output stream
to write DISPLAY output to.
I am arguing that if display_errors is enabled, then this output should
go to /dev/stderr, not to /dev/stdout. 

[EMAIL PROTECTED] describes a workaround that co-opts use of error_log
file from its intended purpose (logging errors to a file, for archival
purposes) in order to redirect display output.

Most well-behaved programs distinguish between 'normal' display output
and 'errors' and use /dev/stdout and /dev/sterr appropriately, in this
regard.
PHP breaks this convention by displaying errors on /dev/stdout instead
of /dev/stderr UNLESS you employ the workaround of setting /dev/stderr
as the logfile.

If sniper's workaround is employed, however, then this prevents logging
errors to a file. 

The behavior of PHP appears confused.

PHP should offer two clearly separated output mechanisms to the
programmer:
1. echo() - for sending 'normal' output to /dev/stdout
2. trigger_error() - for sending 'errors' to /dev/stderr

In my case, I am running php scripts via cron. I always want to
maintain a historical record, via error_log, but I also need cron to
email any true errors immediately - I don't want to set error_log =
/dev/stderr and lose the historical error_log record in order to
accomplish this simple task that would be a no-brainer if my script was
written in bash instead of php.

------------------------------------------------------------------------

[2003-03-24 06:33:07] [EMAIL PROTECTED]

Works fine when you have set it correctly in php.ini:

# php -d log_errors=1 -d error_log=/dev/stderr -r "f();" 1>/dev/null


------------------------------------------------------------------------

[2003-03-24 02:14:59] gk at proliberty dot com

Error messages should go to /dev/stderr instead of /dev/stdout

Example: redirect STDOUT to /dev/null; notice error message does not
appear below:
[EMAIL PROTECTED] php4-STABLE-200303210630]# sapi/cli/php -r "f();" 1>/dev/null
[EMAIL PROTECTED] php4-STABLE-200303210630]# 

This is what you should see on /dev/stderr:
[EMAIL PROTECTED] php4-STABLE-200303210630]# sapi/cli/php -r "f();"

Fatal error: Call to undefined function:  f() in Command line code on
line 1


The problem is due to the default error handler; if you install a
custom error handler function with set_error_handler() then you can work
around the problem for errors except the following which CANNOT be
handled with set_error_handler() function: 
E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR and
E_COMPILE_WARNING. 



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=22839&edit=1

Reply via email to