tp框架快取問題.求解決
活泼星辰
活泼星辰 2017-10-16 14:12:57
0
2
1408

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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!