PHP中实现生成静态文件的方法缓解服务器压力_php技巧

WBOY
Release: 2016-05-17 08:51:31
Original
893 people have browsed it

互联网快速普及的现在社会,越来越多的人会在一个web应用上进行交流,因而导致服务器与数据库访问压力与日俱增,这边就需要进行一些优化,譬如增加缓存、二级缓存、动态网页静态化以及其他的高端技术。

此处作者是使用生成静态文件的方法:

复制代码 代码如下:

/**
* @desc 生成静态文件时使用
* @todo htmlcache
* @param $root string html文件存放路径
* @param $rule string html文件命名规则
* @param $url string 需要生成HTML文件的动态网页地址
* @return boole true/false
*/
public function setHtmlCache($root,$rule,$url){
//检测是否生成过静态文件
if (file_exists($root.$rule.'.html')){//已经存在静态文件
@unlink($root.$rule.'.html');//删除静态文件
return file_put_contents($root.$rule.'.html', file_get_contents($url));//重新生成
}else{//不存在静态文件直接生成
return file_put_contents($root.$rule.'.html', file_get_contents($url));
}
}

该段方法是最普通的生成静态文件方式,欢迎大家进行交流沟通!
Related labels:
php
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!