Home > Article > Backend Development > PHP controls page browser cache and enables gzip transmission_PHP tutorial
This article will introduce to you how to control page browser caching in PHP and enable gzip page transmission. I hope this code will be helpful to you. At the same time, friends who do not have server permissions can implement server gzip page transmission in this way.
php instance gzip transfer page
The code is as follows | Copy code | ||||||||
//Cache expiration time (Cache-Control, http1.1 protocol), recommended to use $secs = 0; //Seconds header("Cache-Control: s-maxage=$secs, max-age=$secs, must-revalidate, proxy-revalidate");
$expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; Header($expire);//Last-Modified, the time of the last modification $gmt_mtime = gmdate('D, d M Y H:i:s', time() ) . ' GMT'; header("Last-Modified: " . $gmt_mtime );
|
The code is as follows | Copy code |
|
Restart your apache and it will be KO
iis enables gzip page transfer
1. Open Internet Information Services (IIS) Manager, right-click "Website" -> "Properties" and select "Services". Select "Compress Application Files" and "Compress Static Files" in the "HTTP Compression" box, and set the "Temporary Directory" and "Maximum Limit of Temporary Directory" as needed;
2. In the Internet Information Services (IIS) Manager, right-click "Web Service Extensions" - "Add a new Web Service Extension..." and enter the extension name in the "New Web Service Extension" box. HTTP Compression", add the "Required File" as C:WINDOWSsystem32inetsrvgzip.dll, where the Windows system directory may be different depending on your installation, check "Set extension status to Allow";
3. Use a text editor to open C:WindowsSystem32inetsrvMetaBase.xml (it is recommended to back up first),
Find Location="/LM/W3SVC/Filters/Compression/gzip to set gzip compression,
Find Location="/LM/W3SVC/Filters/Compression/deflate" to set deflate compression. The two nodes above are next to each other. And the properties set are the same.
If you need to compress dynamic files, set HcDoDynamicCompression to "TRUE",
And add the dynamic file suffix you want to compress in HcScriptFileExtensions, such as aspx;
If static files need to be compressed, set HcDoStaticCompression and HcDoOnDemandCompression to "TRUE",
And add the suffix name of the static file you need to compress in HcFileExtensions, such as xml, css, etc.;
HcDynamicCompressionLevel and HcOnDemandCompLevel represent the required compression rate, the value is 0-10, and the default is 0.
HcDynamicCompressionLevel property description: HcDynamicCompressionLevel Metabase Property
HcOnDemandCompLevel property description: HcOnDemandCompLevel Metabase Property
Note: It is generally recommended to set the value of these two attributes to 9, which has the best cost performance.
Attention
1. You need to stop IIS before editing MetaBase.xml. You can use net stop iisadmin
2. After the modification is completed, start the iisadmin service and execute the iisreset command
About SEO testing
Whether compression has any impact on SEO? After testing, it can still be well included after being turned on.
For research articles on the impact on SEO, you can also refer to the following articles.
Specific efficiency issues will continue to be monitored for research