我试图在Disqus Disqus函数中添加缓存机制:
<?php
ini_set('display_errors', 'on');
$key="MY_PUBLIC_KEY";
$forum="MY_FORUM";
$limit = '5';
$endpoint = 'http://disqus.com/api/3.0/posts/list.json?api_key='.urlencode($key).'&forum='.$forum.'&limit='.$limit.'&related=thread';
$cache_disqus = '/cache_path/file.json';
$j=0;
listposts($endpoint,$j);
function listposts($endpoint,$j) {
// Standard CURL
$session = curl_init($endpoint);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($session);
curl_close($session);
if(file_exists($cache_disqus) && filemtime($cache_disqus) > time() - 1000){
// If a cache file newer than 1000 seconds exists, use it
$results = json_decode($cache_disqus);
} else {
$results = json_decode($data);
file_put_contents($cache_disqus,json_encode($data));
}
}
?>
当然/ cache_path /已正确设置权限。
我得到Warning: file_put_contents(): Filename cannot be empty in MY_SCRIPT_FILENAME.php
。