Example #1
0
function _leiphp_request_method_router()
{
    // 如果已调用APP::end(),则不再执行此函数,因为在die后仍然会执行register_shutdown_function注册的函数
    if (APP::$is_exit) {
        return;
    }
    // 执行相应的请求方法
    $method = strtolower($_SERVER['REQUEST_METHOD']);
    $funcname = "method_{$method}";
    define('APP_TIMESTAMP_ROUTE', microtime(true));
    if (function_exists($funcname)) {
        $funcname();
    } elseif (function_exists('method_all')) {
        $funcname = 'method_all';
        method_all();
    } else {
        $funcname = 'method_undefine';
    }
    // 关闭数据库连接
    @SQL::close();
    // 显示调试信息
    $accept_type = strtolower(trim($_SERVER['HTTP_ACCEPT']));
    if (APP::$is_debug && substr($accept_type, 0, 9) == 'text/html') {
        $spent2 = round((microtime(true) - APP_TIMESTAMP_ROUTE) * 1000, 3);
        $spent = round((microtime(true) - APP_TIMESTAMP_START) * 1000, 3);
        $debug = DEBUG::clear();
        echo "<div style='\n      font-size: 14px;\n      line-height: 1.6em;\n      text-align: left;\n      color: #000;\n      padding: 12px 8px;\n      border: 1px solid #DDD;\n      font-family: \"Microsoft yahei\", \"Helvetica Neue\", \"Lucida Grande\", \"Lucida Sans Unicode\", Helvetica, Arial, sans-serif !important;\n      background-color: #EEE;\n      margin-top: 50px;\n'>Debug<br>Function {$funcname} spent: {$spent2}ms<br>Total spent: {$spent}ms<br>\n<hr><pre style='\n      font-family: \"Microsoft yahei\", \"Helvetica Neue\", \"Lucida Grande\", \"Lucida Sans Unicode\", Helvetica, Arial, sans-serif !important;\n'>{$debug}</pre>\n</div>";
    }
}
Example #2
0
function _slimphp_request_method_router()
{
    // 如果已调用APP::end(),则不再执行此函数,因为在die后仍然会执行register_shutdown_function注册的函数
    if (APP::$is_exit) {
        return;
    }
    // 执行相应的请求方法
    // strtolower(string)
    // 参数	描述
    // string	必需。规定要转换的字符串。
    // 技术细节
    // 返回值:	返回转换为小写的字符串。
    // $_SERVER['REQUEST_METHOD'] #访问页面时的请求方法。例如:“GET”、“HEAD”,“POST”,“PUT”。
    $method = strtolower($_SERVER['REQUEST_METHOD']);
    //得到是get或者post然后下面拼接method_get或者method_post
    $funcname = "method_{$method}";
    //microtime() 函数返回当前 Unix 时间戳和微秒数。
    define('APP_TIMESTAMP_ROUTE', microtime(true));
    if (function_exists($funcname)) {
        $funcname();
    } elseif (function_exists('method_all')) {
        $funcname = 'method_all';
        method_all();
    } else {
        $funcname = 'method_undefine';
    }
    // 关闭数据库连接
    @SQL::close();
    // 显示调试信息
    // $_SERVER['HTTP_ACCEPT'] #当前请求的 Accept: 头部的内容。
    $accept_type = strtolower(trim($_SERVER['HTTP_ACCEPT']));
    //substr(string,start,length)
    //参数	描述
    //string	必需。规定要返回其中一部分的字符串。
    //start
    //必需。规定在字符串的何处开始。
    //正数 - 在字符串的指定位置开始
    //负数 - 在从字符串结尾开始的指定位置开始
    //0 - 在字符串中的第一个字符处开始
    //length
    //可选。规定被返回字符串的长度。默认是直到字符串的结尾。
    //正数 - 从 start 参数所在的位置返回的长度
    //负数 - 从字符串末端返回的长度
    if (APP::$is_debug && substr($accept_type, 0, 9) == 'text/html') {
        //APP_TIMESTAMP_ROUTE  25行
        $spent2 = round((microtime(true) - APP_TIMESTAMP_ROUTE) * 1000, 3);
        $spent = round((microtime(true) - APP_TIMESTAMP_START) * 1000, 3);
        $debug = DEBUG::clear();
        echo "<div style='\n      font-size: 14px;\n      line-height: 1.6em;\n      text-align: left;\n      color: #000;\n      padding: 12px 8px;\n      border: 1px solid #DDD;\n      font-family: \"Microsoft yahei\", \"Helvetica Neue\", \"Lucida Grande\", \"Lucida Sans Unicode\", Helvetica, Arial, sans-serif !important;\n      background-color: #EEE;\n      margin-top: 50px;\n'>Debug<br>Function {$funcname} spent: {$spent2}ms<br>Total spent: {$spent}ms<br>\n<hr><pre style='\n      font-family: \"Microsoft yahei\", \"Helvetica Neue\", \"Lucida Grande\", \"Lucida Sans Unicode\", Helvetica, Arial, sans-serif !important;\n'>{$debug}</pre>\n</div>";
    }
}