PHP 缓存后的代码 [如何]

PHP Codes After Caching [How to]

我的 php 代码有问题。我正在使用具有此功能的简单缓存系统。

// Cache Function
function cachestart($min){
    global $here;
    global $cachefile;
    $cachedosyasi = 'cache/' . 'file' . md5($here);
    if(file_exists($cachefile) && (time() - $min*60 < filemtime($cachefile))){
    include($cachefile);
    die;
    }else{
        ob_start();
        global $cache;
        $cache = 1;
    }
}

function cachefinish(){
    global $cache;
    global $cachefile;
    if(@$cache){
        $ch = fopen($cachefile, 'w');
        fwrite($ch, ob_get_contents());
        fclose($ch);
        ob_end_flush(); 
    }
}

我正在尝试:

-- Some Queries (Controls, is user logged etc. )
<< Start Caching >> (With cachestart() )
-- Some Queries (Show entries in database. )
<< Stop Caching >> (With cachefinish() )
-- Some Queries (Comment box)

但我不能这样做,因为 "die"。我对此一无所知。

感谢您的帮助!

所以这并不完美,但是使用您现有的代码;只需 return truefalse 并让您的应用程序基于此做出决定:

function cachestart($min){
    global $cachefile;
    if(file_exists($cachefile) && (time() - $min*60 < filemtime($cachefile))){
        include($cachefile);
        //we are not caching
        return false;
    } else {
        ob_start();
        //we are caching
        return true;
    }
}

在开始申请时做出决定:

if(!cachestart(60)) {
    //page loaded from cache
    //maybe do some queries for comment box
    die(); //or call cachefinish() with a die() in there
}

//main application code