我正在使用phpfastcachehttps://github.com/khoaofgod/phpfastcache/
当我试图删除缓存时,我得到了一个错误
Warning: unlink(C:'...//sqlite/indexing): Permission denied in C:'...drivers'sqlite.php on line 328
当有一个进程没有释放这些文件的句柄时,我通常会看到这种错误。
复制的步骤
// Require phpfastcache
require_once 'phpfastcache_v2.1_release'phpfastcache'phpfastcache.php';
// Simple singleton
class MyCache extends phpFastCache
{
private static $istance;
Private $obCache;
function __construct()
{
$option = array('securityKey' => 'aCache', 'path' => dirname(__FILE__));
$this->obCache = parent::__construct('sqlite', $option);
}
public static function getIstance()
{
if( is_null(self::$istance) )
{
self::$istance = new self();
}
return self::$istance;
}
}
// check if cached
if( $CacheData = MyCache::getIstance()->get('aKeyword') )
{
die('Cached');
}
// store in cache
MyCache::getIstance()->set('aKeyword','aValue', 60*60*24);
// clean cache (throw error)
MyCache::getIstance()->clean();
die('No cached');
这是生成错误的"phpfastcache"方法
function driver_clean($option = array()) {
// delete everything before reset indexing
$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file != "." && $file!="..") {
unlink($this->path."/".$file);
}
}
}
有人知道怎么解决这个问题吗?
我暂时使用@unlink()
我试过了,但没有改变
chmod($this->path."/".$file, 0777);
unlink($this->path."/".$file);
更新
我在窗户下面。。。
更新2
我使用管理员帐户安装了XAMPP,安装后以管理员权限运行。。。
更新3
解决方案:
function driver_clean($option = array()) {
// close connection
$this->instant = array();
$this->indexing = NULL;
// delete everything before reset indexing
$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file != "." && $file!="..") {
unlink($this->path."/".$file);
}
}
}
解决方案取决于为脚本提供服务的环境。
如果是CLI,则创建、删除或修改文件的能力由执行用户控制。
如果它是一个PHP堆栈(WAMP、XAMPP、ZendServer或自己的Webserver+PHP+MySQL堆栈),执行层(apache、nginx)必须使用一个有权做你想做的事情的用户。
在这两种情况下,它都取决于您配置了什么,或者继承到脚本、目录或驱动器的内容。
可以在此处找到权限知识:http://technet.microsoft.com/en-us/library/cc770962.aspx
(在Windows下不工作)尝试更改之前的权限:
chmod($yourfile, '0777');
unlink($yourfile);