Using the method of generating static files to solve the access pressure on servers and databases, the following is a good tutorial. if you are interested, you can refer to the current society where the internet is rapidly popularized, more and more people will communicate with each other on a web application. as a result, the access pressure on servers and databases is increasing, so we need to make some optimizations, such as adding caching, secondary caching, static dynamic web pages, and other high-end technologies.
Here, the author uses the method to generate static files:
The code is as follows:
/**
* @ Desc used to generate static files
* @ Todo htmlcache
* @ Param $ root string html file storage path
* @ Param $ rule string html file naming rules
* @ Param $ url string the dynamic webpage address of the HTML file to be generated
* @ Return boole true/false
*/
Public function setHtmlCache ($ root, $ rule, $ url ){
// Check whether static files have been generated
If (file_exists($root.$rule.'.html ') {// A static file already exists.
@ Unlink(mongoroot.mongorule.'.html '); // delete a static file
Return file_put_contents($root.$rule.'.html ', file_get_contents ($ url); // regenerate
} Else {// no static file exists to be directly generated
Return file_put_contents($root.$rule.'.html ', file_get_contents ($ url ));
}
}
This section is the most common method for generating static files. You are welcome to communicate with us!