PHP implements static file generation to relieve server pressure

Source: Internet
Author: User
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!

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.