#22839 [Bgs->Opn]: Error messages go to STDOUT instead of STDERR
| From: | gk at proliberty dot com | Date: | Fri, 29 Jun 2007 20:13:59 +0000 |
| Subject: | #22839 [Bgs->Opn]: Error messages go to STDOUT instead of STDERR | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-114470@lists.php.net to get a copy of this message | ||
ID: 22839
User updated by: gk at proliberty dot com
Reported By: gk at proliberty dot com
-Status: Bogus
+Status: Open
Bug Type: CGI related
Operating System: linux RH 7.2
PHP Version: 4CVS-2003-03-24 (stable)
New Comment:
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.
sniper@php.net 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.
Previous Comments:
------------------------------------------------------------------------
[2003-03-24 06:33:07] sniper@php.net
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:
[root@p3 php4-STABLE-200303210630]# sapi/cli/php -r "f();" 1>/dev/null
[root@p3 php4-STABLE-200303210630]#
This is what you should see on /dev/stderr:
[root@p3 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