Implementation of static file generation in PHP to ease server pressure _php tips

Source: Internet
Author: User
The rapid popularization of the Internet in today's society, more and more people will be in a Web application to communicate, resulting in server and database access pressure is increasing, this side needs to do some optimization, such as increased cache, level two cache, Dynamic Web page static and other high-end technology.

The author here uses the method of generating a static file:
Copy Code code as follows:

/**
* Use when generating static files @desc
* @todo Htmlcache
* @param $root string HTML file to store the path
* @param $rule string HTML file naming rules
* @param $url string to generate the Dynamic Web page address of the HTML file
* @return Boole True/false
*/
Public Function Sethtmlcache ($root, $rule, $url) {
Detect whether static files have been generated
if (file_exists $root. $rule. HTML ')) {//static file already exists
@unlink ($root. $rule. HTML ');//delete static files
Return file_put_contents ($root. $rule. HTML ', file_get_contents ($url));//Regenerate
}else{//no static file direct generation
Return file_put_contents ($root. $rule. HTML ', file_get_contents ($url));
}
}

This section method is the most common generation of static file mode, Welcome to communicate!

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.