实际上,我使用的是"标准"会话管理器配置:http://framework.zend.com/manual/current/en/modules/zend.session.manager.html
我想使用缓存并将会话的数据保存到服务器的缓存(memcached)中,以提高性能和可扩展性
我这样设置php.ini(localhostmemcached):
session.save_handler=memcached
session.save_path= "tcp://127.0.0.1"
它显示了这个错误:
Warning: session_start(): Cannot find save handler 'memcached' - session startup failed in C:Program Files (x86)xampphtdocsZend-applicationvendorzendframeworkzendframeworklibraryZendSessionSessionManager.php on line 98
所以,我不知道如何配置我的config/autoload/global.php
和module/application/module.php
。这是我第一次想要实现memcached和缓存。非常感谢!
我试着这样修改module/application/module.php
:
---add session and cache ---
use ZendSessionConfigSessionConfig;
use ZendSessionContainer;
use ZendCacheStorageFactory;
use ZendSessionSaveHandlerCache;
use ZendSessionSessionManager;
use ZendSessionValidatorHttpUserAgent;
use ZendSessionValidatorRemoteAddr;
--- end session and cache ---
public function onBootstrap($e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$this->initSession(array(
'remember_me_seconds' => 180,
'use_cookies' => true,
'cookie_httponly' => true,
'validators' => array(
'ZendSessionValidatorRemoteAddr',
'ZendSessionValidatorHttpUserAgent',
'phpSaveHandler' => 'memcached',
'savePath' => 'tcp://127.0.0.1',
)
));
}
public function initSession($config)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->getValidatorChain()
->attach(
'session.validate',
array(new HttpUserAgent(), 'isValid')
)
->attach(
'session.validate',
array(new RemoteAddr(), 'isValid')
);
$cache = StorageFactory::factory(array(
'adapter' => array(
'name' => 'memcached',
'options' => array(
'server' => '127.0.0.1',
),
)
));
$saveHandler = new Cache($cache);
$sessionManager->setSaveHandler($saveHandler);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
但它显示了这个错误:
Warning: ini_set() expects parameter 2 to be string, array given in C:Program Files (x86)xampphtdocsZend-applicationvendorzendframeworkzendframeworklibraryZendSessionConfigSessionConfig.php on line 88
Fatal error: Call to undefined method ZendStdlibCallbackHandler::attach() in C:Program Files (x86)xampphtdocsZend-applicationmoduleApplicationModule.php on line 68
这是我的config/autoload/global.php
return array(
'db' => array(
'driver' => 'Pdo_Mysql',
'charset' => 'utf-8',
'dsn' => 'mysql:dbname=mydb;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES 'UTF8''
),
),
'service_manager' => array(
'factories' => array(
'ZendDbAdapterAdapter' => 'ZendDbAdapterAdapterServiceFactory',
),
),
'session' => array(
'config' => array(
'class' => 'ZendSessionConfigSessionConfig',
'options' => array(
'name' => 'zend-application',
),
),
'storage' => 'ZendSessionStorageSessionArrayStorage',
'validators' => array(
'ZendSessionValidatorRemoteAddr',
'ZendSessionValidatorHttpUserAgent',
),
),
);
希望它能帮助别人,我解决了我的问题。我在Win7环境下工作,memcached不起作用!我改了:
session.save_handler=memcached
session.save_path= "tcp://127.0.0.1"
至
session.save_handler=memcache
session.save_path= "tcp://127.0.0.1:11211"
我恢复了"标准"会话管理器配置,memcache正常工作。当我将整个站点转移到apache服务器时,我将更改php.ini以使用memcached。
http://framework.zend.com/manual/current/en/modules/zend.session.manager.html