ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

show_php_error error handling function does not abide by display_errors

December 07, 2011 1:29pm

Subscribe [2]
  • #1 / Dec 07, 2011 1:29pm

    Ian Cook

    93 posts

    I’ve been trying to find out why PHP errors still pop up on my production site, and tracked it down to the custom error handler in use by Codeigniter bundled with EE 2.3.1.

    The only thing it seems to check for to decide if it should show a PHP error or not is if the severity matches the error reporting level.

    I have error reporting set to report all errors, because I want all errors to get logged. But I don’t want ANY errors to be displayed.

    I had to change the following to get EE to act how I want:

    system/codeigniter/system/core/Common.php:449

    if (ini_get('display_errors') != 'off')
    {
       $_error->show_php_error($severity, $message, $filepath, $line);
    }

    I have $debug = 0 set in my EE config.php file, and I have all other php.ini settings configured to log errors and not display them.

    Is there a setting I’m missing somewhere?

    I’d prefer to not have to maintain this hack through future EE updates.

    Thanks!

  • #2 / Dec 08, 2011 12:39pm

    Kevin Smith's avatar

    Kevin Smith

    4784 posts

    Hi Ian,

    You shouldn’t have to hack EE at all to achieve what you’re looking to achieve. First, navigate in the CP to Admin > System Administration > Output and Debugging, and make sure Debug Preference is set to only show PHP errors to Super Admins. You as a Super Admin do want to see them so that you can fix them, but you don’t want other users of the site, on the front-end or in the CP, to see them at all.

    Second, you can work with your host on setting up the error log that’s configured in php.ini. EE and CI have no control over that at all.

    If I’ve misunderstood your predicament, please let me know what you’re seeing and what you’d like to see instead.

  • #3 / Dec 08, 2011 1:25pm

    Ian Cook

    93 posts

    Hi Kevin,

    All php logging options are set and working.

    In the Output and Debugging CP, i have it set to Zero (because I have $debug = 0 set in the main config.php file). Changing it to 1 doesn’t seem to affect the issue.

    I don’t want errors on the site shown at all, whether for Super Admins or not. I check the php error logs to see php errors, since they’ll all be there forever, and not just transiently on screen at some random time for some random user.

    It certainly seems like these errors should not show up considering my settings, but they do regardless of being logged in as a Super Admin or not.

    Thanks!

    Ian

  • #4 / Dec 09, 2011 6:27pm

    Kevin Smith's avatar

    Kevin Smith

    4784 posts

    Hi Ian,

    I think the problem here might be that you have $debug = 0 set in the main config.php file. You can place that setting in the main index.php file to suppress errors on the front-end and in admin.php and system/index.php to suppress errors on the backend, but it doesn’t have any effect if you put it in config.php.

    If you put that setting in the appropriate place, does it have the desired effect?

  • #5 / Dec 09, 2011 6:51pm

    Ian Cook

    93 posts

    Whups, I was not clear enough when I said that. Here’s what I have:

    config.php:

    $config['debug'] = 0;

    index.php:

    $debug = 0;
  • #6 / Dec 13, 2011 1:38pm

    Dan Decker

    7338 posts

    Hi Ian,

    Placing

    $config['debug'] = 0;

    In config.php is indeed a valid Config Override in ExpressionEngine 2. Placing that setting there “outweighs” its value in any other location, including the Control Panel.

    So, with that value set, and the hack reverted, are you still not able to see the errors logged?

  • #7 / Dec 13, 2011 5:33pm

    Ian Cook

    93 posts

    Errors are being logged to my specified error logging file. This is not the issue.

    The problem is, PHP errors that get caught by the CI error handler get output to the browser via $_error->show_php_error(), regardless of by debug settings or php.ini / .htaccess / ini_set settings.

    When I do a phpinfo() output at the site of any given error, I can verify that things are set the way I expect, and indeed, everything on that end works as expected.

    But somehow, the CI error handler is outputting error HTML.

    Is there a way to echo the config setting that activates show_php_error function display?

  • #8 / Dec 19, 2011 2:42pm

    Dan Decker

    7338 posts

    Hi Ian,

    I think there have been some crossed signals here, so I’m going to ask that we take a step back and get as clear a picture as possible.

    Can you outline a few things for me so that we can get a good sense of behavior and expectations?
    What is ExpressionEngine doing that you expect it not to be doing?
    Where do you expect to be able to change the behavior you are seeing and where have you made adjustments to effect that change?
    What behavior would you like to see from ExpressionEngine as it relates to this issue?

    Thanks!

  • #9 / Dec 19, 2011 3:10pm

    Ian Cook

    93 posts

    What is ExpressionEngine doing that you expect it not to be doing?

    When a PHP “error” (notice, warning, etc) occurs, EE outputs the error in HTML to the user’s web browser. Since I have explicitly turned off user-visible error output (see below for how), I would expect that these errors would not be output.

    Where do you expect to be able to change the behavior you are seeing and where have you made adjustments to effect that change?

    Primarily, php.ini settings (actually set via ini_set before the EE loader gets executed). Here’s what that looks like for my set up:

    define('SITE_STATUS', 'prod');
        ini_set('session.save_path', '/usr/home/username/tmp/sess/');
        ini_set('display_startup_errors', 'off');
        ini_set('display_errors', 'off');
        ini_set('html_errors', 'off');
        ini_set('log_errors', 'on');
        ini_set('ignore_repeated_errors', 'off');
        ini_set('ignore_repeated_source', 'off');
        ini_set('report_memleaks', 'on');
        ini_set('track_errors', 'on');
        ini_set('docref_root', '0');
        ini_set('docref_ext', '0');
        ini_set('error_log', '/usr/home/username/h/ee2_svn/logs/php.log');
        ini_set('error_reporting', '-1');
        ini_set('log_errors_max_len', '0');
        ini_set('xdebug.collect_params', '0');

    The above code is included at the top of the site’s public index.php. I can verify all settings are taking effect by checking phpinfo().

    In addition to the above, I have debug = 0 set in index.php and I have $config[‘debug’] = 0 set in config.php, as noted above in this thread.

    The only other change I’ve made is on line 180 of the EE public index.php. Here’s the relevant section and then my modification:

    ORIGINAL:

    /*
     * --------------------------------------------------------------------
     *  Set the error reporting level
     * --------------------------------------------------------------------
     */
     if (DEBUG == 1)
     {
      error_reporting(E_ALL);
      @ini_set('display_errors', 1);
     }
     else
     {
      error_reporting(0); // this line is what changes
     }

    MY CHANGE:

    /*
     * --------------------------------------------------------------------
     *  Set the error reporting level
     * --------------------------------------------------------------------
     */
     if (DEBUG == 1)
     {
      error_reporting(E_ALL);
      @ini_set('display_errors', 1);
     }
     else
     {
      error_reporting(error_reporting()); // this is the changed line
     }

    I made this change because I want my error_reporting level preserved. I don’t want to have to enable debug mode in order to get PHP error logging.

     

    Here’s the code and comments that determine if EE should show the HTML error or not:

    system/codeigniter/system/core/Common.php:~449

    // Should we display the error? We'll get the current error_reporting
      // level and add its bits with the severity bits to find out.
      if (($severity & error_reporting()) == $severity)
      {
       $_error->show_php_error($severity, $message, $filepath, $line);
      }

    It would seem that EE is only checking if my error_reporting level is high enough to catch this particular error. Since I want to log all errors I have error reporting set to -1.

    What behavior would you like to see from ExpressionEngine as it relates to this issue?

    As noted at the top of this thread, changing the if clause to ini_get display_errors fixes this issue for me. My thinking is that if I have gone to the trouble to turn off errors displaying to my users, EE should abide by that setting.


    An interesting side effect of using an error handler is also occuring… Any php function prepended with the @ error suppression character does not actually get its error level suppressed. This is because errors still get sent to the error handler, regardless of the @ sign.

    I do not make it a practice of supressing errors with the @ character, but many, many third party plugins do for things such as fopen, etc. All of these supposed-to-be-suppressed errors get output to the browser as well, due to the error handler.


    I hope this helps explain my problem.

    Thanks for sticking with me.

    Ian

  • #10 / Dec 21, 2011 3:14pm

    Dan Decker

    7338 posts

    Ian,

    I brought this up with Kevin and one of our developers so that we could get a complete picture on what is going on here. What may not be entirely clear here is how ExpressionEngine handles error reporting. So that we can get a solid base for your expectations and the result, I need to ask you to back out all of the changes you have made, with everything back to default values. Also make sure to remove your custom ini_sets in index.php
    In index.php:

    $debug = 0

    In /system/expressionengine/config/config.php

    $config['debug'] = 1

    With the default values, ExpressionEngine will only report PHP errors to the browser if the logged in user is in the Super Admin group. Regular visitors are not shown errors by default.

    If you back out all your changes and view the site while you are logged out, are the errors still displayed to the browser? If you are logged in as a Super User, are the errors displayed to the browser?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases