-
Notifications
You must be signed in to change notification settings - Fork 0
/
top.php
52 lines (47 loc) · 1.35 KB
/
top.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
define('ROOT_PATH', dirname(__FILE__));
$name = $_POST['name'];
$seconds = $_POST['seconds'];
$list = read_static_cache('list');
if(!$list){
$list[0] = [
'name' => $name,
'score' => $seconds
];
}else{
$len = count($list);
$list[$len] = [
'name' => $name,
'score' => $seconds
];
}
if(write_static_cache('list', $list)) {
$last_names = array_column($list,'score');
array_multisort($last_names,SORT_ASC,$list);
echo json_encode($list);
}
// 存入本地文件
function write_static_cache($cache_name, $caches) {
$cache_file_path = ROOT_PATH.'/'.$cache_name.'.php';
$content = "<?php\r\n";
$content .= "\$data = ".var_export($caches, true).";\r\n";
$content .= "?>";
file_put_contents($cache_file_path, $content, LOCK_EX);
return true;
}
// 读取本地文件
function read_static_cache($cache_name) {
static $result = array();
if (!empty($result[$cache_name])) {
return $result[$cache_name];
}
$cache_file_path = ROOT_PATH.'\\'.$cache_name.'.php';
if (file_exists($cache_file_path)) {
include_once($cache_file_path);
$result[$cache_name] = $data;
return $result[$cache_name];
}else{
return false;
}
}
?>