2

Zend_Session_SaveHandler_DbTableを使用して、セッションをテーブルに保存しています

私のプロファイラーは、各ページのリクエストでzendが行うことを教えてくれます:

#クエリ時間

(1)接続0.0032038688659668

(2)DESCRIBE session 0.0041539669036865

(3)SELECT session。* FROM sessionWHERE(((sessionsession_id= '7nnan8ltd6h64sigs6dlkicvh0'AND sessionsave_path=''AND sessionname='PHPSESSID')))0.00057697296142578

合計時間:0.008秒

他のテーブルでクエリを実行する場合、zendはそれらを1回(そのテーブルに初めてアクセスするときに)DESCRIBEします。次に、ページを更新すると、Describeなしでクエリのみが実行され、セッションテーブルではすべてのページでDESCRIBEが実行されます(認証を使用する...)

セッションテーブルのメタデータのみをキャッシュするにはどうすればよいですか?

私は現在これを使用しています

class Gestionale_Application_Resource_Cache extends Zend_Application_Resource_ResourceAbstract{
public function init ()
{
    $options = $this->getOptions();

    // Get a Zend_Cache_Core object

    //valori che vengono presi dal file di configurazione
    $cache = Zend_Cache::factory(
        $options['frontEnd'],
        $options['backEnd'],
        $options['frontEndOptions'],
        $options['backEndOptions']);
    Zend_Registry::set('cache', $cache);

    Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);//per mettere in cache la meta-info
    return $cache;
}

これは私の設定ファイルです

...
;cache stuff
resources.cache.frontEnd = core 
resources.cache.backEnd = file 
resources.cache.frontEndOptions.lifetime = 1200 ; in secondi
resources.cache.frontEndOptions.automatic_serialization = true 
resources.cache.backEndOptions.lifetime = 3600 ; in secondi
resources.cache.backEndOptions.cache_dir = APPLICATION_PATH "/../cache"
pluginPaths.Gestionale_Application_Resource = APPLICATION_PATH "/../library/Gestionale/Application/Resource"  
;;fine cache stuff

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.db.params.charset = "utf8"
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "gestionale"
resources.db.isDefaultTableAdapter = true
autoloaderNamespaces[] = "Gestionale_";serve per caricare il plugin di sotto quando si usa anche ZFdebug
resources.frontController.plugins.acl = "Gestionale_Controller_Plugin_Acl"
resources.db.params.profiler = true
...

これは私のセッションテーブルです

CREATE TABLE IF NOT EXISTS `session` (
  `session_id` char(32) NOT NULL,
  `save_path` varchar(32) NOT NULL,
  `name` varchar(32) NOT NULL DEFAULT '',
  `modified` int(11) DEFAULT NULL,
  `lifetime` int(11) DEFAULT NULL,
  `session_data` text,
  PRIMARY KEY (`session_id`,`save_path`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ありがとう

4

2 に答える 2

2

ブートストラップまたは構成ファイルのいずれかでセッション保存ハンドラーを初期化する場合は、必ず最初にZend_Db_Table_Abstract :: setDefaultMetadataCache()を呼び出してください。

;;fine cache stuff設定ファイルで指定するには、次の行の後にセッション設定を配置します。

...
;cache stuff
resources.cache.frontEnd = core 
resources.cache.backEnd = file 
resources.cache.frontEndOptions.lifetime = 1200 ; in secondi
resources.cache.frontEndOptions.automatic_serialization = true 
resources.cache.backEndOptions.lifetime = 3600 ; in secondi
resources.cache.backEndOptions.cache_dir = APPLICATION_PATH "/../cache"
pluginPaths.Gestionale_Application_Resource = APPLICATION_PATH "/../library/Gestionale/Application/Resource"  
;;fine cache stuff

resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary[] = "session_id"
resources.session.saveHandler.options.primary[] = "save_path"
resources.session.saveHandler.options.primary[] = "name"
resources.session.saveHandler.options.primaryAssignment[] = "sessionId"
resources.session.saveHandler.options.primaryAssignment[] = "sessionSavePath"
resources.session.saveHandler.options.primaryAssignment[] = "sessionName"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "session_data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.db.params.charset = "utf8"
...

または、構成ファイルでの順序に依存したくない場合は_initSession()、ブートストラップクラスにメソッドを追加して、それらを正しい順序で具体的にロードすることができます。

protected function _initSession()
{
    $this->bootstrap('cache');
    $this->bootstrap('session');
}
于 2011-06-01T19:32:02.220 に答える
1

'dbMetadataCache'という名前のキャッシュを指定する必要があります。これにより、すべてのテーブルのメタデータがキャッシュされます。

これは、APCをバックエンドとして使用する例です。

resources.cachemanager.dbMetadataCache.frontend.name = "Core"
resources.cachemanager.dbMetadataCache.frontend.options.automatic_serialization = 1
resources.cachemanager.dbMetadataCache.frontend.options.caching = 1
resources.cachemanager.dbMetadataCache.backend.name = "Apc"

resources.db.defaultMetadataCache = "dbMetadataCache"
于 2011-06-01T09:48:07.507 に答える