存档

2010年1月22日 的存档

前几天写过一篇巧用404.php解决Wordpress耗资源的问题,给Wordpress加个缓存功能(http://www.miaoqiyuan.cn/p/wordpress-haoziyuan-wordpress-cache)中提到了PHP缓存的方法,总感觉不是很方便,现在我又写了一个新的。

< ?php
class cache404{
public $K,$P;
public function __construct($URI,$P='blog',$Par='./cache/'){
$this->U = $URI;
$this->K = md5($URI);
$this->P = $P;
$this->Par = $Par;
$this->E = ‘.tmp_miaoqiyuan’;
$this->F = $this->Par . $this->P . ‘/’ . $this->K . $this->E;
}
public function getCache(){
if(!!($fp=@fopen($this->F,’r'))){
$html=fread($fp,102400);
}else{
$html=file_get_contents($this->U);
$this->addIndex();
$fp=fopen($this->F,’w');
fwrite($fp,$html);
}
fclose($fp);
return $html;
}
public function noCache(){
$html=file_get_contents($this->U);
$fp=fopen($this->F,’w');
fwrite($fp,$html);
fclose($fp);
return $html;
}
public function flushCache(){
unlink($this->F);
}
public function addIndex(){
$fpidx=fopen($this->Par . $this->P . ‘.rtf’,'a’);
fwrite($fpidx,$this->K . ‘ ‘ .$this->U);
fclose($fpidx);
}
}
?>

用的时候很简单

require_once(‘./inc/404cache.php’);
$Cache=new cache404($URI,$Path);
#echo $Cache->noCache();
echo $Cache->getCache();

< ?php
require_once('./inc/404cache.php');
$q=explode("/",$URI=substr(($qs = strtolower($_SERVER['QUERY_STRING'])),strpos($qs, ':80')+4));
$URI="/".$URI;
switch($q[0]){
case 'test':
#/test -> /seo_test/test.asp
if(preg_match(‘/^\/test(\/)?$/’,$URI)){
$URI=’http:’.'//’.$_SERVER['SERVER_NAME'].’/seo_test/test.asp’;
}

#/test/[a-z]\.html -> /seo_test/test.asp?key=$1
else [...]

一 22nd, 2010 | Filed under Experience(经验), PHP, Share(分享), Thinks(想法)
标签: , , ,

现在经常用到ISAPI_Rewrite,遇到的问题就是在本地测试的时候,一切没有问题,到服务器上,竟然不起作用。郁闷~
经过我的一些探索,发现了比起作用的原因如下:
1、IIS_WPG对ISAPI_Rewrite.dll没有读取的权限
2、IIS_WPG对httpd.ini没有读取的权限
3、IIS_WPG对站点目录中的httpd.ini没有读取的权限(用于每个站点有独立的httpd.ini)。
4、IIS_WPG对站点目录中没有写入的权限(ISAPI_Rewrite要写入一个httpd.parse.errors文件)。
基本上就是这个问题了,如果是启动进程池的用户不是IIS_WPG组的,请修改成相应的用户有足够的权限。34这两个问题可能经常有朋友会遇到,ISAPI_Rewrite安装好了,只有在ISAPI_Rewrite的安装目录的httpd.ini起作用,对于Web站点根目录的站点无效。其实就是IIS_WPG组对站点目录没有读取的权限,ISAPI_Rewrite是用IIS_WPG组的用户执行的。

一 22nd, 2010 | Filed under Experience(经验)
标签: ,