TP framework cache problem. Please solve it
活泼星辰
活泼星辰 2017-10-16 14:12:57
0
2
1475

59ddd7337bac2.png


##The picture above is my code... access the url interface connection of a website in tp.... When this connection is opened in the browser, the data is different every time it is refreshed... But in tp, it is the same data every time it is refreshed. It is the new data that is refreshed every other time... It should be tp Caching problem... I'm new to TP writing projects... I don't know how to solve it... I'm here to ask for help... (I tried adding a random number parameter after the link...(&t=rand (1,999999) It doesn’t work if you want tp to think that you are visiting a different link every time...),

This is a help post from tp’s official website: http://www.thinkphp.cn/topic /52220.html


活泼星辰
活泼星辰

reply all(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;

	}


路过

Personally I think it’s a problem with the time set by your curlopt_timeout parameter

You have 30 lines of code. Please uncheck it and try.

  • reply No. It's still the same... I've attached the code... You can try it and see if it's just mine.
    活泼星辰 author 2017-10-16 15:47:42
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template