function shutdown()
{
	$error=error_get_last();
	if(is_array($error))
	{
	   if($error['type']==E_ERROR || $error['type']==E_CORE_ERROR || $error['type']==E_COMPILE_ERROR) // Håndterer fatal errors
	   {
			$feilmelding=now();
			foreach($error as $value)
			{
				$feilmelding.=" - $value";
			}
			logFatal($feilmelding);
			header("Location: error.php");
		}
		if($error['type']==E_WARNING || $error['type']==E_PARSE) // Håndterer warning og parse
	   {
			$feilmelding=now();
			foreach($error as $value)
			{
				$feilmelding.=" - $value";
			}
			logError($feilmelding);
		}
	}
}
예제 #2
0
파일: MRedis.php 프로젝트: yanhaojie/buddy
 private function __construct($node = 'redis')
 {
     $this->redis = new Redis();
     $config = C('redis.' . $node);
     if (empty($config)) {
         logFatal(__CLASS__ . '/' . __FUNCTION__ . ":get redis.{$node} config error");
     }
     try {
         $this->redis->connect($config['host'], $config['port']);
     } catch (Exception $e) {
         logFatal(__CLASS__ . '/' . __FUNCTION__ . ":connet redis server error");
     }
 }
예제 #3
0
 public static function instance($node = 'search')
 {
     $conf = C('search.' . $node);
     if (empty($conf)) {
         logFatal(__CLASS__ . '/' . __FUNCTION__ . ":config error,please check");
     }
     $cl = new self();
     $cl->SetServer($conf['host'], $conf['port']);
     $cl->SetConnectTimeout($conf['timeout']);
     $cl->SetArrayResult(true);
     $cl->SetMatchMode(SPH_MATCH_ANY);
     return $cl;
 }
예제 #4
0
파일: Rewrite.php 프로젝트: laiello/fastphp
 private static function parseActionKey()
 {
     global $_FASTPHP_REWRITE_RULE;
     // 解析 Path & Query
     $path = $_SERVER['REQUEST_URI'];
     $query = "";
     $pos = strpos($path, "?");
     if ($pos !== false) {
         $query = substr($path, $pos);
         $path = substr($path, 0, $pos);
     }
     // 解析 Home Path
     $homePath = __HOME_URL;
     if ($homePath == "" || substr($homePath, -1) != "/") {
         logFatal("__HOME_URL must end with '/'.");
     } else {
         if (substr($homePath, 0, 7) == "http://" || substr($homePath, 0, 8) == "https://") {
             $pos = strpos($homePath, "/", 10);
             if ($pos !== false) {
                 $homePath = substr($homePath, $pos);
             } else {
                 $homePath = "/";
             }
         }
     }
     if (defined("__REWRITE_RULE_MODE") == false || __REWRITE_RULE_MODE == "CLOSE") {
         return self::getDefaultActionKey($homePath, $path);
     }
     $homePathLen = strlen($homePath);
     $pathLen = strlen($path);
     if ($pathLen < $homePathLen || $homePath != substr($path, 0, $homePathLen)) {
         return self::getDefaultActionKey($homePath, $path);
     }
     $path = substr($path, $homePathLen - 1);
     //提取URL中的静态化参数部分
     $parsedParams = array();
     $staticParamStr = "";
     if ($pathLen > 5 && substr($path, -4) == ".htm") {
         //静态化参数必须以 .htm 结尾
         $pos = strrpos($path, '/');
         $staticParamStr = substr($path, $pos + 1, -4);
         //最后一个 "/" 与 ".htm" 之间的内容
         $path = substr($path, 0, $pos);
         //不包含结尾的“/”
         $pathLen = $pos;
     } else {
         if (substr($path, -1) == '/') {
             $path = substr($path, 0, -1);
             //移除结尾的“/”
             $pathLen--;
         }
     }
     //URL规则匹配
     $find_actionkey = null;
     foreach ($_FASTPHP_REWRITE_RULE as $key => &$config) {
         if (empty($config['rule'])) {
             continue;
         }
         if ($pathLen == 0) {
             //特殊情形 - 首页地址
             if ($config['rule'] == "/") {
                 $find_actionkey = $key;
                 break;
             }
             continue;
         }
         $preRule = "";
         foreach (explode("|", $config['rule']) as $str) {
             if ($str == "") {
                 continue;
             }
             $preRule .= $str;
             $rule = $preRule;
             if (substr($rule, -1) == "/") {
                 $rule = substr($rule, 0, -1);
             }
             $ruleLen = strlen($rule);
             $pos = strpos($rule, '{');
             if ($pos === false) {
                 if ($rule == $path) {
                     //没有表达式,结尾没有 “/”
                     $find_actionkey = $key;
                     break;
                 }
                 continue;
             }
             if ($pos >= $pathLen || substr($rule, 0, $pos) != substr($path, 0, $pos)) {
                 continue;
             }
             //正则匹配
             $regex = "";
             $varNames = array();
             for ($i = 0; $i < $ruleLen; $i++) {
                 if ($rule[$i] == '/') {
                     $regex .= "\\/";
                 } else {
                     if ($rule[$i] == '{') {
                         //do check
                         //if($rule[$i+1] != '$') {
                         //}
                         $i += 2;
                         //跳过 “{$”
                         //$rule[$i] = "";
                         $varName = "";
                         for (; $i < $ruleLen; $i++) {
                             if ($rule[$i] == '}') {
                                 $i++;
                                 //跳过 }
                                 break;
                             }
                             $varName .= $rule[$i];
                         }
                         if (!empty($config['type'][$varName])) {
                             $regex .= "(" . $config['type'][$varName] . ")";
                             $varNames[] = $varName;
                         } else {
                             logDebug("[RewriteRule] ActionKey: {$key}, Rule={$rule}, IgnoreVariable={$varName}.");
                         }
                     } else {
                         $regex .= $rule[$i];
                     }
                 }
             }
             $matches = array();
             if (@preg_match("/^{$regex}/", $path, $matches)) {
                 //找到了
                 //提取变量
                 foreach ($varNames as $index => $varName) {
                     $parsedParams[$varName] = FastPHP_Request::decode($matches[$index + 1]);
                 }
                 $find_actionkey = $key;
                 break;
             }
         }
         if ($find_actionkey !== null) {
             break;
         }
     }
     if ($find_actionkey !== null) {
         //解析自动静态化变量
         if ($staticParamStr != "") {
             $arr = explode("--", $staticParamStr);
             foreach ($arr as $str) {
                 $arr2 = explode("-", $str, 2);
                 $parsedParams[$arr2[0]] = FastPHP_Request::decode($arr2[1]);
             }
         }
         //已有变量的优先级高
         $_GET = array_merge($parsedParams, $_GET);
         $_REQUEST = array_merge($parsedParams, $_REQUEST);
         return $find_actionkey;
     } else {
         return self::getDefaultActionKey($homePath, $path);
     }
 }