File Cache, PHP file cache _ php Tutorial-PHP Tutorial

Source: Internet
Author: User
File Cache, php file cache. File Cache. php file cache is not much to say. check the code Head. php? Phpdefine (CACHE_EXPIRE, 1800); set the Expiration Time define (CACHE_PATH, $ _ SERVER [DOCUMENT_ROOT]. file cache, php file cache

Read the code.

Head. php

 // This method obtains the number of user refreshes. if the user refreshes twice in a row, the latest function refreshTimes () {$ currentUrl = 'http: // 'is displayed ://'. $ _ SERVER ["HTTP_HOST"]. $ _ SERVER ['request _ URI ']; if (isset ($ _ COOKIE ['refreshtimes']) {$ cookArray = explode ("\ t ", $ _ COOKIE ['refreshtimes']); if (isset ($ cookArray [1]) and $ _ SERVER ['request _ time']-(int) $ cookArray [1] <REFRESH_EXPIRE and isset ($ cookArray [0]) and $ cookArray [0] ==$ currentUrl) {setcookie ('refreshtimes ', $ curren TUrl. "\ t ". $ _ SERVER ['request _ time']. "\ t ". (string) (int) $ cookArray [2] + 1), 0, '/'); return (int) $ cookArray [2];} else {setcookie ('refreshtimes', $ currentUrl. "\ t ". $ _ SERVER ['request _ time']. "\ t1", 0, '/'); return 0 ;}} else {setcookie ('refreshtimes', $ currentUrl. "\ t ". $ _ SERVER ['request _ time']. "\ t1", 0, '/'); return 0 ;}$ key = md5 ($ _ SERVER ['request _ URI ']); $ path = CACHE_PATH. $ key; if (is_file ($ path) and filemtime ($ Path) + CACHE_EXPIRE> $ _ SERVER ['request _ time'] and refreshTimes () = 0) {readfile ($ path); exit ();} ob_start ();?>

Foot. php

 

Test. php

 
 <? Php echo $ title?>
 
 

// Others can see the full PHP file cache

View http://www.cnblogs.com/coolid/archive/2012/09/14/2684373.html links

Let's just talk about the code Head. php? Phpdefine ('cache_expire ', 1800); // Set the Expiration Time define ('cache_path', $ _ SERVER ['document_root '].'/...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.