Simple page buffering technology 2

Source: Internet
Author: User
My specific implementation example is to help you have a perceptual knowledge. here I will show how to implement file-based processing on my homepage. Only the main processing code is incomplete. $ #@ 60 ;? 1 $ tmpfile ../tmp/. basename ($ REQUEST_URI); 2 $ tmpfilestr_replace (?, SyntaxHi

My specific implementation example
To help you have a perceptual knowledge, I will provide a file-based processing method on my homepage. Only the main processing code is incomplete.
$ #@ 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) // use an existing file
19 {
20 readfile ($ tmpfile );
21 exit;
22}
23
24 // create a new file
25 include "template. class. php3 ";
26
27 $ fp = fopen ($ incfile, "r ");
28 $ content = fread ($ fp, filesize ($ incfile ));
29 fclose ($ fp );


30
31 // process the template below
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;
First, I would like to introduce my directory structure:
/--- Bin/execution program directory
| -- Content. php3: The program used to process file display
| -- Template/directory used to store template files
| --- Content. ihtml template file
|-Docs/data file
|-Tmp/stores cached files

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.