Home > Backend Development > PHP Tutorial > Use PHP to realize static WEB dynamic web pages_PHP tutorial

Use PHP to realize static WEB dynamic web pages_PHP tutorial

WBOY
Release: 2016-07-20 11:04:58
Original
1121 people have browsed it

In recent years, the World Wide Web (also known as the World Wide Web, or WWW) has continued to change the face of information processing technology. The Web has quickly become an effective medium for people and businesses to communicate and collaborate. Almost all information technology fields are generally affected by the WEB. Web access brings more users and more data, which means more stress on servers and databases and slower and slower response times for end users. Compared with constantly increasing CPU, disk drives and memory to keep up with this growing demand, staticizing WEB dynamic web pages should be a more practical and economical choice.
The specific implementation function of using PHP to realize the staticization of WEB dynamic web pages is 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;
$cmd_str = "/usr/local/php4/bin /php " . $program1 . " } " . $filename1 . " ";
system($cmd_str);
echo $filename . " generated.〈br〉";
}
This function It is the key to achieve staticization, that is, the PHP dynamic page program is not sent to the browser, but is entered into a file named $filename (Figure 2). Among the two parameters, $program is the PHP dynamic page program, $filename is the name of the generated static page (you can make your own naming rules according to your needs, this is very important, see below), /usr/local/php4/bin/php is PHP has the function of inputting programs into files. System is the function in PHP that executes external commands. We can also see that all PHP programs that generate dynamic pages need to be placed in the /php/ directory, and all newly generated static pages will appear in the /static_html/ directory (these paths can be set according to specific needs).
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); // *.php file is used when fetching 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 has been staticized and turned into 33 static pages college.static0.html~college.static33.html, where $filename will follow $ It changes with the change of I. Of course, you can also get the value directly from the database to control the number and name of the generated static pages. The calling rules of the generated static pages by other programs should be consistent with the naming rules of the static pages. 🎜>

http://www.bkjia.com/PHPjc/445161.html

truehttp: //www.bkjia.com/PHPjc/445161.htmlTechArticleIn recent years, the World Wide Web (also known as the World Wide Web, or WWW) has continued to change the face of information processing technology. The WEB has quickly become an effective medium for people and business communication...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template