tp框架缓存问题.求解决
活泼星辰
活泼星辰 2017-10-16 14:12:57
[PHP讨论组]

59ddd7337bac2.png


上图是我的代码...在tp中访问一个网站的url接口连接....这个连接在浏览器上打开每次刷新的数据都是不一样的...但是在tp中每次刷新都是同样的数据,,隔段时间刷新才是新的数据,...应该就是tp的缓存问题...刚接触tp写项目...不太清楚怎么解决...在这里求助一下...(我试过在链接后面加上一个随机数字的参数...(&t=rand(1,999999) 想让tp认为每次访问的都是不一样的链接都不行...),

这是tp官网求助帖:http://www.thinkphp.cn/topic/52220.html


活泼星辰
活泼星辰

全部回复(2)
活泼星辰
public function index()
	{
		
		$url = 'http://www.kuaishou.com/rest/photos?pcursor=1';
		$ks_data = $this->get_curl($url);
		dump(json_decode($ks_data));
	}

	private function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		$klsf[] = "Accept:*";
		$klsf[] = "Accept-Encoding:gzip,deflate,sdch";
		$klsf[] = "Accept-Language:zh-CN,zh;q=0.8";
		curl_setopt($ch, CURLOPT_HTTPHEADER, $klsf);
		if ($post) {
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
		}
		if ($header) {
			curl_setopt($ch, CURLOPT_HEADER, TRUE);
		}
		if ($cookie) {
			curl_setopt($ch, CURLOPT_COOKIE, $cookie);
		}
		if ($referer) {
			if ($referer == 1) {
				curl_setopt($ch, CURLOPT_REFERER, "http://m.qzone.com/infocenter?g_f=");
			} else {
				curl_setopt($ch, CURLOPT_REFERER, $referer);
			}
		}
		if ($ua) {
			curl_setopt($ch, CURLOPT_USERAGENT, $ua);
		} else {
			curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0');
		}
		if ($nobaody) {
			curl_setopt($ch, CURLOPT_NOBODY, 1);
		//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);//跟随重定向
		}
		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$ret = curl_exec($ch);
		curl_close($ch);
		return $ret;

	}


路过

个人认为是你的 curlopt_timeout  参数设置的时间的问题

你代码30行 注掉试试

  • 回复 不行.还是一样..我把代码附上..大家可以试试看.是不是只有我的有问题
    活泼星辰 作者 2017-10-16 15:47:42
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号