簡單的頁面緩衝技術二_PHP教程

來源:互聯網
上載者:User
我的具體實現的例子
  為了協助大家有個感性認識,這裡我給出在我的首頁上實現的基於檔案處理的方法。只有主要的處理代碼,不完整。
$#@60;?
1 $tmpfile="../tmp/".basename($REQUEST_URI);
2 $tmpfile=str_replace("?", "_", $tmpfile);
3 $tmpfile=str_replace("&", "_", $tmpfile);
4 if(file_exists($tmpfile))
5 {
6 $cflag=false;
7 $dtmp=filemtime($tmpfile);
8 $itmp=filemtime($incfile);
9 $cflag=$cflag | ($dtmp $#@60; $itmp);
10 $ctmp=filemtime(basename($PHP_SELF));
11 $cflag=$cflag | ($dtmp $#@60; $ctmp);
12 $ttmp=filemtime("template/content.ihtml");
13 $cflag=$cflag | ($dtmp $#@60; $ttmp);
14 }
15 else
16 $cflag=true;
17
18 if(!$cflag) //使用存在的檔案
19 {
20 readfile($tmpfile);
21 exit;
22 }
23
24 //建立新的檔案
25 include "template.class.php3";
26
27 $fp=fopen($incfile, "r");
28 $content=fread($fp, filesize($incfile));
29 fclose($fp);

30
31 //下面進行模版處理
32 $t = new Template("template", "keep");
33
34 $t-$#@62;set_file("contentfile","content.ihtml");
35
36 $t-$#@62;set_var(
37 array(
38 "content"=$#@62;$content
39 ));
40
41 $t-$#@62;parse("outputcontent","contentfile");
42
43 $fp=fopen($tmpfile, "w");
44 if($fp)
45 {
46 flock($fp, 3);
47 fwrite($fp, $t-$#@62;get_var("outputcontent"));
48 flock($fp, 1);
49 fclose($fp);
50 }
51 $t-$#@62;p("outputcontent");
?$#@62;
  先向大家介紹一下我的目錄結構:
  /---bin/ 執行程式目錄
  | |--content.php3 用於處理檔案顯示的程式
   | |--template/ 用於存放模板檔案的目錄
   | |---content.ihtml 模板檔案
   |-docs/ 資料檔案
   |-tmp/ 存放緩衝檔案

http://www.bkjia.com/PHPjc/531740.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/531740.htmlTechArticle我的具體實現的例子 為了協助大家有個感性認識,這裡我給出在我的首頁上實現的基於檔案處理的方法。只有主要的處理代碼,不完整。...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.