Using latest yii-1.1.8.r3324 running with php 5.3.6 on apache 2.2
PHP is set in php.ini to log but not display errors:
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL | E_STRICT
error_log = /var/www/errors/php-errors
YII_DEBUG and YII_TRACE_LEVEL lines are commented out in index.php so that we are running in Production mode.
Now here’s the issue:
When Yii encounters a session_start() call when a session is already started, the app stops and displays:
[b]Error 500
A session had already been started - ignoring session_start()[/b]
and then no further page content except the page footer image.
I would have expected that with YII_DEBUG false, as it is by default with the lines in index commented,
that no errors would be displayed and the script would run as normal. Instead the script is balking over a simple notice error which should only be logged.
Looking inside the framework YiiBase.php found the define YII_ENABLE_ERROR_HANDLER
If I define(‘YII_ENABLE_ERROR_HANDLER’,false) in my index file then the errors don’t show and the scripts produce normal page content.
But I feel I should not have to do that when YII_DEBUG is defined as false.
I am familiar with that reference and as I read it indicates that the default YII behavior is not how PHP works.
What you say would be the case except for the fact that YII overrides the default PHP error handling behavior in CApplication::initSystemHandlers() like so:
By default PHP neither halts for a NOTICE error nor displays it to the user when set in recommended production mode with
error_reporting = E_ALL & ~E_DEPRECATED
and
display_errors = Off
The PHP recommended production error_reporting setting
E_ALL & ~E_DEPRECATED
does not inhibit reporting of NOTICE errors but they are not displayed to the user with display_errors = Off, and scripts are not halted for these type of errors.
When I test outside of YII using simple scripts containing NOTICE errors, those scripts are not halted and no error message is displayed to the user.
However, by contrast, with PHP in recommended production mode, when YII in production mode encounters a simple PHP NOTICE error it both halts (error 500) and displays the NOTICE error.
This is not the default PHP action, i.e., it is not the way PHP works.
There could be many reasons why fopen fails and just halting doesn’t allow us to deal with it. The only option in this case would be to suppress the errors with ‘@’ which is bad practice and makes bugs even harder to find.
With a standard php program it logs the errors but allows you to continue the program.
Halting can be useful at times but I think halting should be opt-in.
If anyone finds a workaround for this in Yii that logs the warnings and notices but doesn’t halt processing, please post it here. I’ll do the same, if I can figure out a way to do it.