用PHP实现WEB动态网页静态化_PHP教程

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

在最近几年,万维网(也称环球信息网,即WWW)不断改变信息处理技术的面貌。WEB已经快速地成为一种有效的媒介,并适合人们和商业沟通和协作。几乎所有的信息技术领域都普遍受到WEB的影响。Web访问带来更多用户和更多数据,这意味着给服务器和数据库更多压力和最终用户得到越来越慢的响应速度。与不断靠增加CPU,磁盘驱动器及内存来跟上这种增长的需求相比, WEB动态网页面静态化应该是一个更实用,更经济的选择。
用PHP实现WEB动态网页静态化的具体实现函数如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〉";
}
这个函数是实现静态化的关键,即PHP动态页面程序不是被送到浏览器中,而是输入到名为$filename的文件中去(如图2)。两个参数中$program是PHP动态页面程序,$filename是生成的静态页面的名字(可根据需要自己制定命名规则,这一点很重要,见下文),/usr/local/php4/bin/php是PHP中具有把程序输入文件功能的部分,System是PHP中执行外部命令的函数。我们还可以看出所有生成动态页面的php程序需放在/php/目录下,所有新产生的静态页面则会出现在/static_html/目录下(这些路径可以根据具体需要设置)。
下面让我们举个具体例子,看一下college_static.php的静态页面是怎样生成的。
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);
}
从这个函数我们可以看到通过调用函数gen_static_file(), college_static.php经过静态化,变成了33个静态页面college.static0.html~college.static33.html,其中$filename会随着$I的变化而变化。当然也可以从数据库中直接取值,来控制生成的静态页面的个数和名字,其他程序对生成的静态页面的调用应和静态页面的命名规则一致。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445161.htmlTechArticle在最近几年,万维网(也称环球信息网,即WWW)不断改变信息处理技术的面貌。WEB已经快速地成为一种有效的媒介,并适合人们和商业沟通...
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!