From d1d1f657136a834cc347e8554f3cc436fa74c757 Mon Sep 17 00:00:00 2001 From: rainerosion <1782832653@qq.com> Date: Sat, 10 Apr 2021 20:21:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'index.php'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/index.php b/index.php index bd59951..dd124de 100644 --- a/index.php +++ b/index.php @@ -1,17 +1,27 @@ 0,'url' => $url,'name' => $name]; - echo json_encode($arr); - } else { - header('Location:'.$url); - } +$memcache = new Memcache; +$memcache->connect('127.0.0.1', 11211) or die ("Could not connect"); +$json = $memcache->get('randUrlJson'); +// echo "获取缓存"; +if(trim($json) == "" || $json == false){ + if(file_exists($file_path)){ + $fp = fopen($file_path,"r"); + $str = fread($fp,filesize($file_path)); + $memcache->set('randUrlJson', $str); + $json = $str; + // echo "设置缓存"; + } +} +$res = json_decode($json,true); +$randNum = rand(0,sizeof($res)-1); +$url = $res[$randNum]['url']; +$name = $res[$randNum]['name']; +if($_GET['return'] == 'json'){ + $arr = ['code' => 0,'url' => $url,'name' => $name]; + echo json_encode($arr); +} else { + // echo $url; + header('Location:'.$url); } \ No newline at end of file