$redisConn = new redisFunc(REDIS_HOST,REDIS_PORT,REDIS_PASS);
} catch(Exception $e) {
echo 'redis连接失敗';
}
}
// 参数(判断是否刷新缓存)
$refresh_cache = 0;
@ -78,14 +86,27 @@ function get_cache() {
global $member_type;
global $cache_type;
global $refresh_cache;
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
if (!$vnum){
return "";
if (REDIS_ON) {
$redisConn = new redisFunc(REDIS_HOST,REDIS_PORT,REDIS_PASS);
if ($redisConn->check(AREA.'-'.$member_type.'-'.$cache_type.'-'.CID.'-'.EP_ID)) {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
if (!$vnum){
return "";
}
@$cache = $vnum['cache'];
@$expired_time = $vnum['expired_time'];
}
@$cache = $vnum['cache'];
@$expired_time = $vnum['expired_time'];
//修复读取问题
$cache = str_replace("u0026", "&", $cache);
$cache = str_replace("\r", "\\r", $cache);
@ -115,7 +136,11 @@ function write_cache() {
global $refresh_cache;
$ts = time();
$array = json_decode($output, true);
$code = $array['code'];
if (is_array($array)) {
$code = $array['code'];
} else {
$code = -404;
}
switch ($code) {
case "0":
// 删掉用户mid
@ -146,13 +171,18 @@ function write_cache() {
$ts = $ts + CACHE_TIME_OTHER;
}
if ($output !== "") { //没有获取到输出内容不写入缓存
$sql = "INSERT INTO `cache` (`expired_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('".$ts."','".AREA."','".$member_type."','".$cache_type."','".CID."','".EP_ID."','".$output."')";
// 刷新缓存
if ($refresh_cache == 1) {
$sql = "UPDATE `cache` SET `expired_time` = '".$ts."', `cache` = '".$output."' WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."';";
if (REDIS_ON) {
$redisConn = new redisFunc(REDIS_HOST,REDIS_PORT,REDIS_PASS);
$sql = "INSERT INTO `cache` (`expired_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('".$ts."','".AREA."','".$member_type."','".$cache_type."','".CID."','".EP_ID."','".$output."')";
// 刷新缓存
if ($refresh_cache == 1) {
$sql = "UPDATE `cache` SET `expired_time` = '".$ts."', `cache` = '".$output."' WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."';";
}
$dbh -> exec($sql);
}
$dbh -> exec($sql);
}
}
}
// 获取season缓存
@ -161,46 +191,91 @@ function get_cache_season() {
global $member_type;
global $cache_type;
global $refresh_cache_season;
if (AREA == "th") {
$area = "th"; //泰区
} else {
$area = "main"; //主站
}
if (EP_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".$area."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '0' AND `ep_id` = '".EP_ID."'";
} elseif (SS_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".$area."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '".SS_ID."' AND `ep_id` = '0'";
} else {
return "";
}
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
if (!$vnum) {
//给主站的一次机会获取自身 AREA 可能 code!=0 的缓存
if ($area == "main") {
if (EP_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '0' AND `ep_id` = '".EP_ID."'";
} elseif (SS_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '".SS_ID."' AND `ep_id` = '0'";
if (REDIS_ON) {
$redisConn = new redisFunc(REDIS_HOST,REDIS_PORT,REDIS_PASS);
if (EP_ID != "") {
if ($redisConn->check($area.'-season-'.$cache_type.'-0-'.EP_ID)){
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".$area."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '0' AND `ep_id` = '".EP_ID."'";
} elseif (SS_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".$area."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '".SS_ID."' AND `ep_id` = '0'";
} else {
return "";
}
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
if (!$vnum) {
//给主站的一次机会获取自身 AREA 可能 code!=0 的缓存
if ($area == "main") {
if (EP_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '0' AND `ep_id` = '".EP_ID."'";
} elseif (SS_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '0' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '".SS_ID."' AND `ep_id` = '0'";
}
$cres = $dbh -> query($sqlco);
$vnum2 = $cres -> fetch();
}
}
@$cache1 = $vnum['cache'];
@$expired_time1 = $vnum['expired_time'];
@$cache2 = $vnum2['cache'];
@$expired_time2 = $vnum2['expired_time'];
if ($cache1 != "") {
$cache = $cache1;
$expired_time = $expired_time1;
} elseif ($cache2 != "") {
$cache = $cache2;
$expired_time = $expired_time2;
} else {
return "";
}
}
if (time() <= (int)$expired_time) {
//修复读取问题
@ -221,10 +296,14 @@ function write_cache_season() {
global $output;
global $cache_type;
global $refresh_cache_season;
$ts = time();
$array = json_decode($output, true);
$code = $array['code'];
if (is_array($array)) {
$code = $array['code'];
} else {
$code = -404;
}
switch ($code) {
case "0":
$ts = $ts + CACHE_TIME_SEASON;
@ -259,29 +338,48 @@ function write_cache_season() {
// 修复转义问题
$output = str_replace("\\", "\\\\", $output);
// 当 code==0 缓存成 area=main
$sql = "INSERT INTO `cache` (`expired_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('".$ts."','".$area."','0','season_".$cache_type."','".$ss_id."','".$ep_id."','".$output."')";
// 刷新缓存
if ($refresh_cache_season == 1) {
$sql = "UPDATE `cache` SET `expired_time` = '".$ts."', `cache` = '".$output."' WHERE `area` = '".$area."' AND `cache_type` = 'season_".$cache_type."' AND `cid` = '".$ss_id."' AND `ep_id` = '".$ep_id."';";
if (REDIS_ON) {
$redisConn = new redisFunc(REDIS_HOST,REDIS_PORT,REDIS_PASS);
$sqlco = "SELECT `expired_time`,`cid` FROM `cache` WHERE `area` = '".$area."' AND `cache_type` = 'subtitle_".$cache_type."' AND `ep_id` = '".$ep_id."'";
@ -296,7 +394,11 @@ function write_cache_season() {