


Introduction to php and browser caching mechanism_PHP tutorial
The browser's caching policy will temporarily cache browsed files on the local disk. When the user repeatedly requests the page, the client is informed that the page has not changed and caching can be called. So how do you know if the client has a page cache? From the HTTP protocol level, when the browser sends a request, it will first send the following
HTTP header:
Connection Keep-Alive
Date Sun, 06 May 2012 18:00:36 GMT
Last-Modified Sun, 06 May 2012 17:31:02 GMT
Etag ec1f629013925ab0fa4389ba926e8c06
Keep-Alive timeout=15, max=299
Server Apache/2.2.16 (Unix) DAV/2
Vary Accept-Encoding
Please note these two lines, which describe the cache information of the page:
Last-Modified Sun, 06 May 2012 17:31:02 GMT
Etag ec1f629013925ab0fa4389ba926e8c06 In this case, if the server responds with a 304 status code, the browser will consciously read the data from the cache; if it responds with a 200 status code, it will still read from the server regardless of whether there is a client cache.
According to this theoretical support, for example, most of the query results of the webmaster army are obtained asynchronously through ajax, and secondary visits can be cached in this way. As long as the client has cache, send a 304 response status code to the client, and then exit the program execution.
The request sent by the browser contains two parameters: If-Modified-Since and If-None-Match:
If-Modified-Since means asking whether the last modification time of the data is a certain time value. Then the server will check the last modification time of the data, and if it is that time, it will return a 304 status code. After receiving the status code, the client will read the cache directly from the local cache. This situation has a precondition, that is, cache resources must exist locally before the browser will send the If-Modified-Since parameter, and the value is the Last-Modified value returned by the last server.
If-None-Match is similar. It is generated by the Etag value returned by the server. It is only used by the server to check the modification time of the data. It can be any value. Considering that the method of If-Modified-Since combined with Last-Modified is not supported by all servers, only the implementation using etag will be considered here.
In PHP, you can use $_SERVER['HTTP_IF_NONE_MATCH'] to determine whether the file is cached by the browser. The code snippet is as follows:
//Use the etag tag to control caching
The code is as follows
|
Copy code
|
||||
$etag = md5 (date('Ymd')); if ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) { | header('Etag:' . $etag);
} Here I use the current date to generate the etag, which ensures The cache will take effect for up to one day, and this parameter can be modified as needed.
www.bkjia.com
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Choose a reliable trading platform such as OKEx to ensure access to the official entrance.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Methods for configuring character sets and collations in MySQL include: 1. Setting the character sets and collations at the server level: SETNAMES'utf8'; SETCHARACTERSETutf8; SETCOLLATION_CONNECTION='utf8_general_ci'; 2. Create a database that uses specific character sets and collations: CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci; 3. Specify character sets and collations when creating a table: CREATETABLEexample_table(idINT

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.
