Example #1
0
function glog_dosyslog($message)
{
    // Пишет сообщение в системный лог при включенной опции GLOG_DO_SYSLOG.
    static $last_invokation_time;
    static $last_memory_usage;
    if (!defined("GLOG_DO_SYSLOG")) {
        define("GLOG_DO_SYSLOG", false);
    }
    if (!defined("GLOG_DO_PROFILE")) {
        define("GLOG_DO_PROFILE", GLOG_DO_SYSLOG);
    }
    if (glog_get_msg_log_level($message) < glog_log_level()) {
        return false;
    }
    if (GLOG_DO_SYSLOG || GLOG_DO_PROFILE) {
        if (!defined("GLOG_SYSLOG")) {
            die("Code: " . __FUNCTION__ . "-" . __LINE__ . "-GLOG_SYSLOG");
        }
        if (!is_dir(dirname(GLOG_SYSLOG))) {
            mkdir(dirname(GLOG_SYSLOG), 0777, true);
        }
        if (!$last_invokation_time) {
            $last_invokation_time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(true);
        }
        if (!$last_memory_usage) {
            $last_memory_usage = memory_get_usage(true);
        }
        $invokation_time = microtime(true);
        $memory_usage = memory_get_usage(true);
        $time_change = round($invokation_time - $last_invokation_time, 4);
        $request_time_change = isset($_SERVER['REQUEST_TIME_FLOAT']) ? round($invokation_time - $_SERVER['REQUEST_TIME_FLOAT'], 4) : 0;
        $memory_change = $memory_usage - $last_memory_usage;
        $data = array(@$_SERVER["REMOTE_ADDR"], date("Y-m-d\\TH:i:s"), GLOG_DO_PROFILE && $request_time_change ? $request_time_change . "s" : "", GLOG_DO_PROFILE ? $time_change . "s" : "", GLOG_DO_PROFILE ? glog_convert_size($memory_usage) : "", GLOG_DO_PROFILE && $memory_change ? glog_convert_size($memory_change) : "", $message);
        $str = implode("\t", $data) . "\n";
        if (file_put_contents(GLOG_SYSLOG, $str, FILE_APPEND) === false) {
            $Subject = "Error in " . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
            $extraheader = "Content-type: text/plain; charset=UTF-8";
            $message = "Can not write data to log file '" . GLOG_SYSLOG . "'!\nUnsaved data:\n" . $message . "\n";
            if ($_SERVER["HTTP_HOST"] == "localhost") {
                die("Code: " . __FUNCTION__ . "-" . __LINE__ . "- \"" . $subject . " - " . $message . "\"");
            } else {
                mail(EMAIL, $Subject, $message, $extraheader);
            }
            return false;
        }
        $last_invokation_time = $invokation_time;
        $last_memory_usage = $memory_usage;
    }
    return true;
}
Example #2
0
    $tmp = glob(SITE_DIR . "functions/*.php");
    foreach ($tmp as $file_name) {
        $site_functions[basename($file_name, ".php")] = $file_name;
    }
    unset($tmp, $file_name);
}
// Determine wich functions to load
$functions_to_load = array_merge($engine_functions, $app_functions, $site_functions);
// Load functions
foreach ($functions_to_load as $code => $file_name) {
    require_once $file_name;
}
require_once ENGINE_DIR . "default_functions.php";
// Site configuration
$CFG_ini = parse_ini_file(cfg_get_filename("settings", "settings.ini", ENGINE_SCOPE_ALL), true);
if ($CFG_ini == false) {
    die("Code CFG INI");
}
$CFG = array_merge_recursive($CFG, $CFG_ini);
//
if (function_exists("get_site")) {
    $_SITE = get_site($sub_domain);
} else {
    $_SITE = null;
}
// Logging level
if (DEV_MODE) {
    glog_log_level("DEBUG");
} else {
    glog_log_level("INFO");
}