@ 2013-06-14T12:59:59Z <?php
// 为避免污染全局命名空间,已对所有标识符加 `e` 前缀
/**
* 运行模式
* * debug 调试模式, 会开启详细的日志记录和错误提示
* * default 默认模式, 会输出错误提示
* * production 生产模式, 不会执行任何额外操作, 最高效地执行代码
*/
ob_start();
const eDebug = 2;
const eDefault = 1;
const eProduction = 0;
const eRunMode = eDebug;
// 默认关掉所有错误提示
error_reporting(0);
// 如果是默认模式,打开致命错误和解析错误的报告
if(eRunMode >= eDefault)
error_reporting(E_ERROR | E_PARSE);
// 如果是调试模式,打开全部错误提示,并启用修改建议提示
if(eRunMode >= eDebug)
error_reporting(E_ALL | E_STRICT);
class ePHPException extends Exception
{
protected $severity;
protected $varList;
public function __construct($message = "", $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, Exception $previous = null, $varList = [])
{
$this->severity = $severity;
$this->file = $filename;
$this->line = $lineno;
$this->varList = $varList;
// 调用父类的构造函数
parent::__construct($message, $code, $previous);
}
public function getSeverity()
{
return $this->severity;
}
public function getVarList()
{
return $this->varList;
}
}
set_error_handler(function($no, $str, $file, $line, $varList)
{
throw new ePHPException($str, 0, $no, $file, $line, null, $varList);
});
register_shutdown_function(function() {
$error = error_get_last();
if($error['type'] === E_ERROR)
throw new ePHPException($error['message'], 0, $error['type'], $error['file'], $error['line']);
});
if(eRunMode <= eProduction)
{
set_exception_handler(function(Exception $exception) {
header("Content-Type: text/plant; charset=UTF-8");
die(header("HTTP/1.1 500 Internal Server Error"));
});
}
else
{
echo "+++";
set_exception_handler(function(Exception $exception) {
echo "---";
// 暂时我们只打算以纯文本的形式展示信息
header("Content-Type: text/plant; charset=UTF-8");
// 整体模版
$msg = "Exception `%s`: %s\nStack trace:\n%s\n thrown in %s on line %s";
// 栈的每一行的模版
$traceline = "#%s %s (%s): %s(%s)";
// 从异常对象获取运行栈
$trace = $exception->getTrace();
// 只有在调试模式才会显示参数的值,其他模式下只显示参数类型
if(eRunMode < eDebug)
foreach ($trace as $key => $stackPoint)
$trace[$key]['args'] = array_map('gettype', $trace[$key]['args']);
$result = [];
// 对运行栈的每一项应用模版
foreach ($trace as $key => $stackPoint)
{
print_r($stackPoint)
$result[] = sprintf(
$traceline,
$key,
$stackPoint['file'],
$stackPoint['line'],
$stackPoint['function'],
implode(', ', $stackPoint['args'])
);
}
$result[] = '#' . ++$key . ' {main}';
// 应用整体模版
$msg = sprintf(
$msg,
get_class($exception),
$exception->getMessage(),
implode("\n", $result),
$exception->getFile(),
$exception->getLine()
);
// 打印运行栈等信息
print $msg;
// 如果当前是调试模式,且异常对象是我们构造的 ePHPException 类型,打印符号表
if(eRunMode >= eDebug && $exception instanceof ePHPException)
print_r($exception->getVarList());
});
}
array_keys(1);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.16 0.020 0.043 12.41 5.4.15 0.031 0.073 12.39 5.4.14 0.016 0.042 12.09 5.4.13 0.013 0.045 12.06 5.4.12 0.022 0.065 12.03 5.4.11 0.026 0.063 12.03 5.4.10 0.015 0.043 12.03 5.4.9 0.014 0.045 12.03 5.4.8 0.021 0.067 12.03 5.4.7 0.022 0.068 12.02 5.4.6 0.016 0.071 12.02 5.4.5 0.022 0.065 12.02 5.4.4 0.020 0.036 12.01 5.4.3 0.016 0.042 12.01 5.4.2 0.015 0.058 12.00 5.4.1 0.015 0.071 12.01 5.4.0 0.016 0.042 11.50 5.3.26 0.015 0.045 12.72 5.3.25 0.013 0.047 12.72 5.3.24 0.066 0.057 12.72 5.3.23 0.021 0.081 12.71 5.3.22 0.030 0.075 12.68 5.3.21 0.023 0.039 12.68 5.3.20 0.018 0.042 12.68 5.3.19 0.025 0.038 12.67 5.3.18 0.021 0.054 12.68 5.3.17 0.015 0.044 12.67 5.3.16 0.025 0.080 12.67 5.3.15 0.010 0.049 12.67 5.3.14 0.016 0.043 12.66 5.3.13 0.014 0.045 12.65 5.3.12 0.026 0.065 12.66 5.3.11 0.017 0.043 12.66 5.3.10 0.009 0.050 12.12 5.3.9 0.012 0.045 12.09 5.3.8 0.030 0.086 12.09 5.3.7 0.026 0.065 12.08 5.3.6 0.014 0.045 12.07 5.3.5 0.020 0.070 12.01 5.3.4 0.013 0.045 12.01 5.3.3 0.023 0.063 11.98 5.3.2 0.027 0.060 11.76 5.3.1 0.023 0.051 11.72 5.3.0 0.014 0.042 11.71
preferences:dark mode live preview
142.65 ms | 1394 KiB | 7 Q