更新 'index.php'

This commit is contained in:
rainerosion 2021-04-10 20:21:36 +08:00
parent 3bb42a5ba4
commit d1d1f65713

View File

@ -1,17 +1,27 @@
<?php <?php
error_reporting(0); error_reporting(0);
$file_path = "data/images.json"; $file_path = "data/images.json";
if(file_exists($file_path)){ $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"); $fp = fopen($file_path,"r");
$str = fread($fp,filesize($file_path)); $str = fread($fp,filesize($file_path));
$res = json_decode($str,true); $memcache->set('randUrlJson', $str);
$randNum = rand(0,sizeof($res)-1); $json = $str;
$url = $res[$randNum]['url']; // echo "设置缓存";
$name = $res[$randNum]['name'];
if($_GET['return'] == 'json'){
$arr = ['code' => 0,'url' => $url,'name' => $name];
echo json_encode($arr);
} else {
header('Location:'.$url);
} }
} }
$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);
}