更新 'index.php'
This commit is contained in:
parent
3bb42a5ba4
commit
d1d1f65713
14
index.php
14
index.php
@ -1,10 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
$file_path = "data/images.json";
|
$file_path = "data/images.json";
|
||||||
|
$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)){
|
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);
|
||||||
|
$json = $str;
|
||||||
|
// echo "设置缓存";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res = json_decode($json,true);
|
||||||
$randNum = rand(0,sizeof($res)-1);
|
$randNum = rand(0,sizeof($res)-1);
|
||||||
$url = $res[$randNum]['url'];
|
$url = $res[$randNum]['url'];
|
||||||
$name = $res[$randNum]['name'];
|
$name = $res[$randNum]['name'];
|
||||||
@ -12,6 +22,6 @@ if(file_exists($file_path)){
|
|||||||
$arr = ['code' => 0,'url' => $url,'name' => $name];
|
$arr = ['code' => 0,'url' => $url,'name' => $name];
|
||||||
echo json_encode($arr);
|
echo json_encode($arr);
|
||||||
} else {
|
} else {
|
||||||
|
// echo $url;
|
||||||
header('Location:'.$url);
|
header('Location:'.$url);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user