views:

22

answers:

0

I have a custom PHP error handler in my application, which displays a friendly error message to the user and logs the error for me to fix.

However, I've noticed since implementing it that when an error occurs in one page, the error is reported from users on unrelated parts of the site. Say it's a error in /some_site_section/view_one.php:

Call to a member function getLinks() on a non-object [/var/www/vhosts/domain.com/httpdocs/views/view_one.php:121]

Requested page: /some_site_section/view_one.php
Logged in user: 4152

I then get several other error messages from other users browsing unrelated parts of the site. The error message is the same, but the requested page and user ID show that the code that's in error couldn't have been triggered (view_one.php and view_two.php are in actuality completely unrelated -- code in one couldn't be called from another, for instance).

Call to a member function getLinks() on a non-object [/var/www/vhosts/domain.com/httpdocs/some_site_section/view_one.

Requested page: /some_other_site_section/view_two.php
Logged in user: 2285

It's almost as if it kills every current session because of the one error. Is that possible? I don't know much about how Apache and PHP interact; is it possible that several users are on the same thread, or something similarly clueless-sounding?

My shutdown function is below; it doesn't do anything particularly special, just gives me a bunch of debug info. It works fine in all other ways except that it seems to trigger shutdown() for all users of the site when it's triggered for one of them.

function shutdown() {

 if (($error = error_get_last()) && !(isset($_REQUEST['isDev']) || _USER_IS_DEV)) {
     if (isset($error['type']) && ($error['type'] == E_ERROR || $error['type'] == E_PARSE || $error['type'] == E_COMPILE_ERROR)) {
            ob_end_clean();

            if (!headers_sent()) {
                header('HTTP/1.1 500 Internal Server Error');
            }

            include "500.php";

            $error_message = $error['message']." [".$error['file'].":".$error['line']."]";

            $error_message .= "\n\nRequested page: " . $_SERVER['REQUEST_URI'];

            $error_message .= "\n\nLogged in user: " . _AUTH_USER_ID . " (" . _AUTH_USERNAME . ")";

            $headers = "";

            foreach (apache_request_headers() as $key => $value) {  
                $headers .= "$key: $value\n";
            }

            $error_message .= "\n\nHeaders: \n\n" . $headers;

            $request = "";

            foreach ($_REQUEST as $key => $value) {  
                $request .= "$key: $value\n";
            }

            $error_message .= "\n\nRequest: \n\n" . $request;

   @mail(_SITE_TECH_EMAIL, "ERROR on public site", $error_message, "From:" . _SITE_TITLE . " <" . _SITE_ADMIN_EMAIL . ">");
        }
    }
}