Static php page notes

Source: Internet
Author: User
Static php page notes,
 Output_buffering: on * Several cache functions: ob_start (); ob_clean (); ob_get_content (); ob_end_clean (); Disable Cache and clear * ob_flush (); outputs and clears the content in the cache, but does not close ob_end_flush (); closes and outputs * // **/ob_start (); // enables the cache echo 'yyy '; // If cache is not enabled, an error is reported. If no header is encountered, php sends a header by default. this header cannot be modified ('content-type: text/htm; charset = utf-8 '); echo '000000'; ob_get_contents (); // Get the cached content ob_end_clean (); echo 'AA '; // put the header in the program cache ('content-type: text/htm; charset = utf-8 '); // An error is reported during running, because the cache has been disabled/** use the cache mechanism provided by php to make a real cache * the content of the truly cached page should not be changed for a long time, in addition, different users see the same thing * principle: when the user first accesses the database, he queries the database and obtains the content in the cache area, and put it in the cache file ** // ***/ob_start (); // The slow-saving file contains $html_filename='static.html '; if (file_exists ($ html_filename) & (filemtime ($ html_filename) + 30)> time () // regenerate after 30 seconds {// Retrieve the cached page content echo file_get_contents ($ html_filename); exit ;} echo 'Ur content'{html_content}ob_get_contents({$html_filename}'static.html '; file_put_contents ($ html_filename, $ html_content);/*** defects of the above principles: 1. insufficient real-time performance 2. not conducive to seo * solution: Update the cache file when the database is added or updated */if ($ _ REQUEST ['AC'] = 'ADD ') // update is also {// Obtain the template file $ template_content = file_get_contents ('Template. tpl '); // replace the tag $ php_content = str_replace ("{",'
 ', $ Template_content); // Generate the cache file $ php_tplname = 'php _ tpl. php '; file_put_contents ($ php_tplname, $ php_content); include (file_put_contents); $ html_content = metadata (); comment'; file_put_contents ($ html_filename, $ html_content );} /*** real static defect: many cached files are generated, which occupy the hard disk * for massive html generation, you can consider using pseudo static files */$ str = '2017, 123 '; preg_match ('/\ d/is', $ str, $ arr ); // Match four consecutive numbers and return to arr. it only matches an arr [0] preg_match ('/ (\ D)/is ', $ str, $ arr); // at this time, arr returns three strings where 0 matches, arr [n] returns the matched string in order of expression // use the preg_match_all () function for all matching requests; note: to enable the rewrite module in apache configuration, you must also set the permission for derecloud allowoverride from all. htacss // the matching rule is top-down. you can set the error page * RewireEngine On * news-id (\ d )\. html $ news. php? Id = $1 * news-id (\ d).html $ error. php # put the error page to the end */

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.