标题: cache问题
cong
新手上路
Rank: 1



UID 1331
精华 0
积分 0
帖子 2
翻译 0
原创 0
阅读权限 10
注册 2008-6-11
状态 离线
发表于 2008-9-30 22:10  资料  短消息  加为好友 
cache问题

无论是用file还是memcached,第一遍没问题可以正常显示,刷新一下就是一片空白,能否帮我看看。。。。

PHP代码如下:

<?php

// set include path
define('APP_DIR',dirname(dirname(__FILE__)));
define('WEB_ROOT',substr(htmlentities($_SERVER['PHP_SELF']), 0strrpos(htmlentities($_SERVER['PHP_SELF']), '/')));

set_include_path('.' PATH_SEPARATOR APP_DIR '/library' PATH_SEPARATOR APP_DIR '/application/default/models/' PATH_SEPARATOR get_include_path());

require_once 
'Initializer.php';
require_once 
'Zend/Loader.php'

// Set up autoload.
Zend_Loader::registerAutoload(); 
Zend_Registry::set('st',microtime());

// Initialize Config
$config = new Zend_Config_Xml(APP_DIR '/config/config.xml''production');
Zend_Registry::set('Config',$config);

// setup the front cache config
$frontend $config->cache->frontendname;
$frontendOptions = array(
    
'lifetime'                   => $config->cache->lifetime// cache lifetime of 2 hours
    
'automatic_serialization' => $config->cache->automatic_serialization
);

// setup the back cache config
$backend $config->cache->backendname;
$backendOptions = array(
    
'servers'    => array(    
        
'host'          => $config->cache->backserver->host,
        
'port'          => $config->cache->backserver->port,
        
'persistent' => $config->cache->backserver->persistent)
);


// Setup the Zend_Cache
$cache Zend_Cache::factory($frontend$backend$frontendOptions$backendOptions);

// start cache load and save
$frontController $cache->load('frontController');
if (!
$frontController instanceof Zend_Controller_Front){
    
// Prepare the front controller. 
    
$frontController Zend_Controller_Front::getInstance(); 
    
// Change to 'production' or 'debug'
    
$frontController->registerPlugin(new Initializer('production'));
    
$cache->save($frontController'frontController');    
}
 
try {
    
$frontController->dispatch();
}catch (
Zend_Controller_Exception $e) {
    
nl2br($e->__toString());
}catch (
Exception $e) {
    
nl2br($e->__toString());
}

unset(
$config);
?>




PHP代码如下:

<?php


require_once 'Zend/Controller/Plugin/Abstract.php';
require_once 
'Zend/Controller/Front.php';
require_once 
'Zend/Controller/Request/Abstract.php';


class 
Initializer extends Zend_Controller_Plugin_Abstract
{
    
/**
     * @var Zend_Config
     */
    
protected static $_config;

    
/**
     * @var string Current environment
     */
    
protected $_env;

    
/**
     * @var Zend_Controller_Front
     */
    
protected $_front;

    
/**
     * @var string Path to application root
     */
    
protected $_root;

    
/**
     * Constructor
     *
     * Initialize environment, root path, and configuration.
     * 
     * @param  string $env 
     * @param  string|null $root 
     * @return void
     */
    
public function __construct($env$root null)
    {
        
$this->_setEnv($env);
        if (
null === $root) {
            
$root realpath(dirname(dirname(__FILE__)));
        }
        
$this->_root $root;

        
$this->initPhpconfig();
        
        
$this->initSession();
              
        
$this->_front Zend_Controller_Front::getInstance();
        
        
// set the test environment parameters
        
if ($env == 'debug') {
            
// Enable all errors so we'll know when something goes wrong. 
            
error_reporting(E_ALL E_STRICT);  
            
ini_set('display_startup_errors'1);  
            
ini_set('display_errors'1); 

            
$this->_front->throwExceptions(true);  
        }
        
        
$this->initLogs();        
    }

    
/**
     * Initialize environment
     * 
     * @param  string $env 
     * @return void
     */
    
protected function _setEnv($env
    {
        
$this->_env $env;        
    }
    

    
/**
     * Initialize initPhpconfig
     * 
     * @return void
     */
    
public function initPhpconfig()
    {

    }
    
    
/**
     * Initialize Session
     * 
     * @return void
     */
    
public function initSession()
    {
        
$session = new Zend_Session_Namespace(Zend_Registry::get('Config')->session_name);
        
Zend_Registry::set('Session',$session);     
    }   

    
/**
     * Initialize Logs 
     * 
     * @return void
     */
    
public function initLogs()
    {
        
$writer = new Zend_Log_Writer_Stream($this->_root '/logs/default.log');
        
$logger = new Zend_Log($writer);
        
Zend_Registry::set('Logger',$logger);
    }    

    
/**
     * Route startup
     * 
     * @return void
     */
    
public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
           
$this->initDb();
        
$this->initHelpers();
        
$this->initView();
        
$this->initPlugins();
        
$this->initRoutes();
        
$this->initControllers();
    }
    
    
/**
     * Initialize data bases
     * 
     * @return void
     */
    
public function initDb()
    {
        
$dbInit Zend_Db::factory(Zend_Registry::get('Config')->database);
        
Zend_Db_Table::setDefaultAdapter($dbInit);
        
//$dbInit->query("SET NAMES 'utf8'");
    
}

    
/**
     * Initialize action helpers
     * 
     * @return void
     */
    
public function initHelpers()
    {

    }
    
    
/**
     * Initialize view 
     * 
     * @return void
     */
    
public function initView()
    {
        
// Init the Smarty view wrapper and set smarty suffix to the view scripts.
        
$view = new EZ_View_Smarty(Zend_Registry::get('Config')->smarty->toArray());
        
        
// Set Layout info
        
$view->headMeta()->appendHttpEquiv('Content-Type''text/html; charset=UTF-8')
                         ->
appendHttpEquiv('Content-Language'Zend_Registry::get('Config')->base_lang)
                         ->
appendName('Keywords'Zend_Registry::get('Config')->site->keyword)
                         ->
appendName('Description'Zend_Registry::get('Config')->site->desc)
                         ->
appendName('Generator'Zend_Registry::get('Config')->site->gen)
                         ->
appendName('Robots'Zend_Registry::get('Config')->site->robots); 
                         
        
$view->headLink()->headLink(array('rel' => 'favicon''href' => WEB_ROOT.Zend_Registry::get('Config')->site->favicon), 'PREPEND');
            
        
$view->headTitle(Zend_Registry::get('Config')->site->title.Zend_Registry::get('Config')->site->info);

        
$et explode(' ',microtime());
        
$st explode(' ',Zend_Registry::get('st'));
        
$runtime $et[1]-$st[1]+$et[0]-$st[0];
        
$view->content 'Powered By Zend framework 1.6.0 , Codz by Cong  Processed in 'number_format($runtime4). ' s.';
        
        
// use the viewrenderer to keep the code DRY
        // instantiate and add the helper in one go
        
$viewRenderer Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        
$viewRenderer->setView($view);
        
$viewRenderer->setViewSuffix(Zend_Registry::get('Config')->smarty->suffix);

        
// Set inflector for Zend_Layout        
        
$inflector = new Zend_Filter_Inflector(':script.:suffix');
        
$inflector->addRules(array(
            
':script' => array('Word_CamelCaseToDash''StringToLower'),
            
'suffix'  => Zend_Registry::get('Config')->smarty->suffix
        
));

        
// Bootstrap layouts                    
          
Zend_Layout::startMvc(array(
            
'layoutPath' => $this->_root Zend_Registry::get('Config')->layout->layoutpath,
            
'layout'      => 'default',
            
'view'          => $view,
            
'contentKey' => Zend_Registry::get('Config')->layout->contentKey,          
            
'inflector'  => $inflector
          
));              
    }
    
    
/**
     * Initialize plugins 
     * 
     * @return void
     */
    
public function initPlugins()
    {

    }
    
    
/**
     * Initialize routes
     * 
     * @return void
     */
    
public function initRoutes()
    {
    
    }

    
/**
     * Initialize Controller paths 
     * 
     * @return void
     */
    
public function initControllers()
    {
        
$this->_front->addControllerDirectory($this->_root '/application/default/controllers''default');
    }
    

}
?>



顶部
cong
新手上路
Rank: 1



UID 1331
精华 0
积分 0
帖子 2
翻译 0
原创 0
阅读权限 10
注册 2008-6-11
状态 离线
发表于 2008-9-30 22:11  资料  短消息  加为好友 
config.xml配置文件

PHP代码如下:

<?xml version="1.0"?>
<configdata>
    <production>
        <base_url>http://www.somesite.com</base_url>
        
        <base_prefix>http://</base_prefix>

        <base_lang>zh-CN</base_lang>
        
        <session_name>idmusic</session_name>
        
        <debugging>false</debugging>
        
        <favicon>/public/images/favicon.ico</favicon>        
            
        <site>    
            <title>IDMUSIC</title>        
            <info> 你的音乐帝国</info>        
            <keyword>IDMUSIC,mp3,iso,daw,samples</keyword>
            <desc>this desc is idmusic</desc>
            <gen></gen>
            <robots>index, follow</robots>
        </site>

        <database>
            <adapter>mysqli</adapter>
            <params>
                <host>localhost</host>
                <username>root</username>
                <password>root</password>
                 <dbname>test</dbname>
            </params>
        </database>
        
        <smarty>
            <suffix>html</suffix>            
            <compiledir>/data/template</compiledir>
        </smarty>
        
        <layout>
            <layoutpath>/application/default/views/layouts</layoutpath>
            <contentkey>content</contentkey>
            <template>Special</template>
        </layout>
    
        <cache>
            <lifetime>7200</lifetime>
            <automatic_serialization>true</automatic_serialization>
            <cachedir>/data/cache</cachedir>
            <frontendname>Core</frontendname>
            <backendname>Memcached</backendname>
            <backserver>
                <host>127.0.0.1</host> 
                <port>11211</port>
                <persistent>false</persistent>
            </backserver>
        </cache>
    </production>
  
      <staging extends="production">
        <debugging>true</debugging>
      </staging>
</configdata>



顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2009-1-10 07:48

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.125373 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver