Dynamic Web page static + local static

Source: Internet
Author: User

Static:

1. Set the cache time

if(Is_file('./index.html ') && ( Time()-Filemtime('./index.html ') < 1200)) {    require_once('./index.html ');}Else {    //Introducing Database Link Operations    require_once('./db.php '); $sql= "SELECT * from news where ' category_id ' = 1 and ' status ' = 1 limit 4"; Try{        $db= Db::getinstance ()Connect (); $result=mysql_query($sql,$db); $newsList=Array();  while($row=Mysql_fetch_assoc($result)) {            $newsList[] =$row; }    }Catch(Exception $e) {        //TODO    }    Ob_start(); require_once(' template/index.php '); $s=ob_get_contents(); file_put_contents('./index.html ',$s); //Ob_clean ();}

Because it is the time of the cache setting, the previous cache cannot be purged, so when a static file is generated earlier, the cache content cannot be retrieved with the Ob_get_clean () function, which caches the cached content, but ob_get_ Contents () will get the cache and will not clear the cache. So use ob_get_contents ();

2. Add a button to select manual Refresh

3.CRONTAB-E timing, time-sharing day and month execution statement

Local Update:

Ajax get method, take the interface, write a JS, get the interface data and then format.

<script>$.ajax ({     "GET",    "http://static.com/demo4/api/ajax.php",    " JSON ",    function(data) {        alert (data.message);    }}); </script>

Dynamic Web page static + local static

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.