Use PHP to implement WEB dynamic web page static_PHP tutorial

WBOY
Release: 2016-07-21 16:07:27
Original
790 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 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 is the key to achieve staticization, that is, PHP dynamic pages The 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 give a specific example to see how the static page of college_static.php is generated.

function gen_college_static ()
function gen_college_static ()
{
for ($i = 0; $i 〈= 32; $i++〉
{
putenv("province_id=" . $i); //*.php文件从数据库取数据时要用到。
$filename = " college_static". $i . ".html";
gen_static_file("college_static.php", $filename);
}
{
for ($i = 0; $i 〈= 32; $i++〉
{putenv("province_id=" . $i); //*.php file when fetching data from the database To be used.

$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 is staticized and becomes 33 static pages college.static0.html~college.static33.html. Among them, $filename will change with the change of $I. Of course, the value can also be obtained directly from the database to control the number and name of the generated static pages. The calls of other programs to the generated static pages should be consistent with the naming of the static pages. The rules are the same. http://www.bkjia.com/PHPjc/315095.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315095.htmlTechArticle
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 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!