Using PHP to implement Dynamic Web page static

Source: Internet
Author: User
Tags implement
Web| News | static | Web page In recent years, the World Wide Web (also known as Global Information Network, WWW) has been changing the face of information technology. The web has quickly become an effective medium for people and business to communicate and collaborate. Almost all information technology areas are generally influenced by the web. Web Access brings more users and more data, which means more pressure on servers and databases and end users getting slower and faster response times. Web Dynamic page Surface statics should be a more practical and economical option than increasing the CPU, disk drives, and memory to keep up with this growing demand.

The implementation function of the Dynamic Web Web page static with PHP is shown in functions like function gen_static_file ()


function Gen_static_file ($program, $filename)
{
$program 1= "/usr/local/apache/htdocs/php/". $program;
$filename 1 = "/usr/local/apache/htdocs/static_html/". $filename;
$cmd _str = "/usr/local/php4/bin/php". $program 1. " } " . $filename 1. " ";
System ($cmd _str);
Echo $filename. "Generated.〈br〉";
}


This function is the key to the implementation of static, that is, the PHP dynamic page program is not sent to the browser, but entered into a file named $filename (see Figure 2). Two parameters in the $program is a PHP dynamic page program, $filename is the name of the generated static page (can be based on the need to make their own naming rules, this is important, see below),/usr/local/php4/bin/ PHP is the part of PHP that has the function of inputting programs into files, and system is the function of executing external commands in PHP. We can also see that all the PHP programs that generate dynamic pages should be placed in the/php/directory, and all new static pages will appear in the/static_html/directory (these paths can be set according to the specific needs).

Let's take a concrete example and see how the college_static.php static page is generated.


function gen_college_static ()
{
for ($i = 0; $i 〈= $i ++〉
{
Putenv ("province_id=". $i); *.php files are used when fetching data from a 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 has been statically transformed into 33 static pages college.static0.html~ College.static33.html, where $filename will change as $i changes. Of course, can also be directly from the database to control the number of static pages generated and name, other programs to generate static page calls should be consistent with the static page naming rules.

Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.