首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >phpfastcache unlink()权限被拒绝

phpfastcache unlink()权限被拒绝
EN

Stack Overflow用户
提问于 2013-12-07 15:47:17
回答 2查看 2.2K关注 0票数 0

我正在使用phpfastcache https://github.com/khoaofgod/phpfastcache/

当我尝试删除缓存时,我会得到一个错误。

代码语言:javascript
复制
Warning: unlink(C:\...//sqlite/indexing): Permission denied in C:\...drivers\sqlite.php on line 328

当有一个进程没有释放这些文件的句柄时,我通常会看到这样的错误。

再生产步骤

代码语言:javascript
复制
// 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“方法。

代码语言:javascript
复制
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()

我试过了,但什么都没有改变

代码语言:javascript
复制
chmod($this->path."/".$file, 0777);
unlink($this->path."/".$file);

更新

我在窗户下面..。

更新2

我使用管理帐户安装XAMPP,安装后使用管理权限运行.

更新3

解决方案:

代码语言:javascript
复制
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);
        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2013-12-07 16:45:51

解决方案取决于为脚本提供服务的环境。

如果是CLI,则创建、删除或修改文件的能力由执行用户控制。

如果是PHP ( WAMP、XAMPP、ZendServer或自己的Webserver+PHP+MySQL-Stack ),则执行层( apache,nginx )必须使用有权做您想做的事情的用户。

在这两种情况下,这都取决于您配置了什么或继承到您的脚本、目录或驱动器中的是什么。

许可知识可以在这里找到:http://technet.microsoft.com/en-us/library/cc770962.aspx

票数 2
EN

Stack Overflow用户

发布于 2013-12-07 15:48:51

(在Windows下不工作)尝试更改权限之前:

代码语言:javascript
复制
chmod($yourfile, '0777');
unlink($yourfile);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20443247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档