没有合适的资源?快使用搜索试试~ 我知道了~
PHP进行远程获取文件、实现了跨服务器获取文件
资源推荐
资源详情
资源评论
$username = 'username';
$tweet_count = '20';
$getjson = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $count . '&include_entities=1&include_rts=1';
$expire = 120; //过期时间,单位秒,2分钟
$cache_file = './sqlite_twitter.dat'; //缓存文件
$arr = array();
clearstatcache();
if (file_exists($cache_file) && time() <= (filemtime($cache_file) + $expire)) {
//缓存文件存在且未过期则直接读取
$arr = unserialize(file_get_contents($cache_file));
echo "********缓存存在且未过期,直接读取缓存数据********";
$timelost = $expire - (time() - filemtime($cache_file));
echo "***********Twitter距离下次更新还剩 $timelost 秒***********";
}else{
//缓存文件不存在或已过期则读取json数据处理并缓存
$content = file_get_contents($getjson); //远程调用
$arr = json_decode($content, true);
if($arr) {
file_put_contents($cache_file, serialize($arr)); //写入缓存文件
echo "*********读取Twitter接口数据成功*********";
}else{
echo "**error**读取Twitter接口数据失败**error**";
$arr = unserialize(file_get_contents($cache_file));
echo "******************|*******************";
echo "******************|*******************";
echo "******************|*******************";
echo "******************|*******************";
echo "******************V*******************";
echo "*********调用缓存数据数据成功*********";
$tweet_count = '20';
$getjson = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $count . '&include_entities=1&include_rts=1';
$expire = 120; //过期时间,单位秒,2分钟
$cache_file = './sqlite_twitter.dat'; //缓存文件
$arr = array();
clearstatcache();
if (file_exists($cache_file) && time() <= (filemtime($cache_file) + $expire)) {
//缓存文件存在且未过期则直接读取
$arr = unserialize(file_get_contents($cache_file));
echo "********缓存存在且未过期,直接读取缓存数据********";
$timelost = $expire - (time() - filemtime($cache_file));
echo "***********Twitter距离下次更新还剩 $timelost 秒***********";
}else{
//缓存文件不存在或已过期则读取json数据处理并缓存
$content = file_get_contents($getjson); //远程调用
$arr = json_decode($content, true);
if($arr) {
file_put_contents($cache_file, serialize($arr)); //写入缓存文件
echo "*********读取Twitter接口数据成功*********";
}else{
echo "**error**读取Twitter接口数据失败**error**";
$arr = unserialize(file_get_contents($cache_file));
echo "******************|*******************";
echo "******************|*******************";
echo "******************|*******************";
echo "******************|*******************";
echo "******************V*******************";
echo "*********调用缓存数据数据成功*********";
资源评论
a397659936
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功