In recent years, the World Wide Web (also known as the World Wide Information Network (WWW) has continuously changed the face of information processing technologies. WEB has quickly become an effective medium for people to communicate and collaborate with businesses. Almost all information technology fields are affected by the WEB. Web access brings more users and more data, which means more pressure on servers and databases and slow response speed for end users. Compared with increasing CPU, disk drive, and memory to keep up with this demand, static WEB pages should be a more practical and economical choice.
Use PHP to implement static WEB pages, as shown in function gen_static_file ().
Function gen_static_file ($ program, $ filename) { $ Program 1 = "/usr/local/apache/htdocs/php/". $ program; $ Filename1 = "/usr/local/apache/htdocs/static_html/". $ filename; $ Pai_str = "/usr/local/php4/bin/php". $ program1. "}". $ filename1 .""; System ($ response _str ); Echo $ filename. "generated. <br> 〉"; } |
This function is the key to static, that is, the PHP dynamic page program is not sent to the browser, but is input to the file named $ filename (2 ). Among the two parameters, $ program is a PHP dynamic page program, and $ filename is the name of the generated Static Page (you can customize naming rules as needed. This is important, see the following description ), /usr/local/php4/bin/php is a part of PHP that provides the function of inputting program files. System is a function used to execute External commands in PHP. We can also see that all php programs that generate dynamic pages should be placed in the/php/directory, all newly generated static pages will appear in the/static_html/directory (these paths can be set as needed ).
Let's take a specific example to see how the static page of college_static.php is generated.
Function gen_college_static () { For ($ I = 0; $ I <=32; $ I ++> 〉 { Putenv ("province_id =". $ I); // * use the PHP file to retrieve data from the database. $ Filename = "college_static". $ I. ". html "; Gen_static_file ("college_static.php", $ filename ); } |
From this function, we can see that by calling the function gen_static_file (), college_static.php goes through the static state and becomes the 33 page college.static0.html ~ College.static33.html, where $ filename changes with $ I. Of course, you can also take values directly from the database to control the number and name of generated static pages. Other programs should call the generated static pages in the same way as the static page naming rules.