コード例 #1
0
ファイル: vb.php プロジェクト: cedwards-reisys/nexus-web
 public static function handleError($errno, $errstr, $errfile, $errline)
 {
     //we should honor the error reporting settings (which the error handler
     //system does *not* do by default -- we get everything here.  We return
     //false so that the default error handler triggers.  It won't display
     //anything either, but it will correctly exit so we don't need to figure
     //out if we have to.
     //php changed the way dispay_errors is reported in version 5.2.  We probably don't
     //have to care about the old way, but this covers all of the bases.
     $display_errors = in_array(strtolower(ini_get('display_errors')), array('on', '1'));
     if (!(error_reporting() & $errno) or !$display_errors) {
         return false;
     }
     //Note that not all of these error codes are trappable and therefore
     //many cannot actually occur here.  They are listed for completeness
     //and possible future proofing if that changes.
     $label = "";
     $fatal = false;
     switch ($errno) {
         case E_STRICT:
             $label = "Strict standards";
             break;
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
             $label = "Notice";
             break;
         case E_WARNING:
         case E_CORE_WARNING:
         case E_USER_WARNING:
         case E_COMPILE_WARNING:
             $label = "Warning";
             break;
         case E_NOTICE:
         case E_USER_NOTICE:
             $label = "Notice";
             break;
         case E_ERROR:
         case E_PARSE:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
         case E_USER_ERROR:
         case E_RECOVERABLE_ERROR:
             $label = "Fatal error";
             $fatal = true;
             break;
             //if we don't know what the error type is, php added it after 5.6
             //we'll punt to the system error handler because we simply don't know
             //what we are dealing with.  This risks leaking the path on files, but
             //that's not as bad as exiting on a warning or not exiting on a fatal error
         //if we don't know what the error type is, php added it after 5.6
         //we'll punt to the system error handler because we simply don't know
         //what we are dealing with.  This risks leaking the path on files, but
         //that's not as bad as exiting on a warning or not exiting on a fatal error
         default:
             return false;
             break;
     }
     if (!defined('DIR')) {
         //if we don't have DIR defined yet, let's show the error and live
         //with the potential path exposure.  Things are really borked.
         $safe_errfile = $errfile;
         $safe_errstr = $errstr;
     } else {
         //make the output safe for public consumption
         $safe_errfile = str_replace(DIR, '...', $errfile);
         $safe_errstr = str_replace(DIR, '...', $errstr);
     }
     $safe_message = "{$label}: {$safe_errstr} in {$safe_errfile} on line {$errline}\n";
     $message = "{$label}: {$errstr} in {$errfile} on line {$errline}";
     //echo the error
     echo $safe_message;
     //try to mimic the logging behavior of the default function
     if (ini_get('log_errors')) {
         error_log($message);
     }
     if ($fatal) {
         //log the error
         if (defined('DIR')) {
             require_once DIR . '/includes/functions_log_error.php';
             log_vbulletin_error($message, 'php');
         }
         $usercontext = vB::getUserContext();
         if (function_exists('debug_print_backtrace') and $usercontext and $usercontext->isAdministrator()) {
             // This is needed so IE doesn't show the pretty error messages
             echo str_repeat(' ', 512);
             echo vB_Utilities::getStackTrace();
         }
         //return a 500 error
         if (!headers_sent()) {
             if (PHP_SAPI == 'cgi' or PHP_SAPI == 'cgi-fcgi') {
                 header('Status: 500 Internal Server Error');
             } else {
                 header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
             }
         }
         exit;
     }
     //we've got this -- no need to bother the default handler
     return true;
 }
コード例 #2
0
ファイル: cache.php プロジェクト: cedwards-reisys/nexus-web
 /** 
  * If cache logging is enabled this stores the page cache activity to be loggged.
  *
  **/
 protected static function logCacheAction($cacheid, $action, $type = 4, $size = 0)
 {
     static $random;
     if (!isset($random)) {
         $random = rand();
     }
     if (!isset(self::$actions[$type][$cacheid])) {
         self::$actions[$type][$cacheid] = array('cacheid' => $cacheid, 'randomkey' => $random, 'type' => $type, 'writes' => 0, 'misses' => 0, 'hits' => 0, 'rereads' => 0, 'remiss' => 0, 'clears' => 0, 'time' => vB::getRequest()->getTimeNow(), 'size' => $size, 'stacktrace' => '');
     }
     // store the most recent stack trace
     self::$actions[$type][$cacheid]['stacktrace'] = vB_Utilities::getStackTrace();
     switch ($action) {
         case self::CACHE_LOG_WRITE:
             self::$actions[$type][$cacheid]['writes'] = 1;
             self::$actions[$type][$cacheid]['size'] = $size;
             break;
         case self::CACHE_LOG_READSUCCESS:
             self::$actions[$type][$cacheid]['hits']++;
             break;
         case self::CACHE_LOG_READFAIL:
             self::$actions[$type][$cacheid]['misses']++;
             break;
         case self::CACHE_LOG_HASVALUE:
             self::$actions[$type][$cacheid]['rereads']++;
             break;
         case self::CACHE_LOG_NOVALUE:
             self::$actions[$type][$cacheid]['remiss']++;
             break;
         case self::CACHE_LOG_CLEAR:
             self::$actions[$type][$cacheid]['clears']++;
             break;
     }
 }