Session memcached cho Zend 1
Session memcached cho Zend 1
File: application/Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
...
protected function _initSessionId()
{
$this->bootstrap('session');
Zend_Session::getSaveHandler()->setCache(My_Memcache::getSessionCache());
}
...
}
File: /library/My/Memcache.php
<?php
class My_Memcache{
private static $_ssinstance;
public static function getSessionCache() {
if(!is_object(self::$_ssinstance))
{
$cacheConf = new Zend_Config_Ini(CONFIG_PATH . '/cache.ini', APPLICATION_ENV);
$memcache = $cacheConf->memcached;
self::$_ssinstance = Zend_Cache::factory($memcache->frontend->name,
$memcache->backend->name,
$memcache->frontend->options->toArray(),
$memcache->backend->options->toArray());
}
return self::$_ssinstance;
}
File: application/configs/application.ini
[production]
;session savehandler class
resources.session.name = ssdomain
resources.session.saveHandler.class = Zend_Session_SaveHandler_Cache
resources.session.gc_maxlifetime = 86400
resources.session.cookie_domain = "domain.vn"
File: application/Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
...
protected function _initSessionId()
{
$this->bootstrap('session');
Zend_Session::getSaveHandler()->setCache(My_Memcache::getSessionCache());
}
...
}
File: /library/My/Memcache.php
<?php
class My_Memcache{
private static $_ssinstance;
public static function getSessionCache() {
if(!is_object(self::$_ssinstance))
{
$cacheConf = new Zend_Config_Ini(CONFIG_PATH . '/cache.ini', APPLICATION_ENV);
$memcache = $cacheConf->memcached;
self::$_ssinstance = Zend_Cache::factory($memcache->frontend->name,
$memcache->backend->name,
$memcache->frontend->options->toArray(),
$memcache->backend->options->toArray());
}
return self::$_ssinstance;
}
}
File: application/configs/application.ini
[production]
;session savehandler class
resources.session.name = ssdomain
resources.session.saveHandler.class = Zend_Session_SaveHandler_Cache
resources.session.gc_maxlifetime = 86400
resources.session.cookie_domain = "domain.vn"