dtf76989 2017-06-28 11:21
浏览 27

ZF3会话超时问题

I have been facing issue related to Session timeout using Zend Framework 3. Session expired within 5-10 min. I had used the default code for the session, which Zf3 skeleton provides in global.php as below.

// Session configuration.
'session_config' => [   
  'cookie_lifetime' => 60*60*1, // Session cookie will expire in 1 hour.
  'gc_maxlifetime' => 60*60*1,  // Store session data on server maximum for 1 hour. 
],

// Session manager configuration. 
'session_manager' => 
[
   'validators' => [
      RemoteAddr::class,
      HttpUserAgent::class,
    ]
],

// Session storage configuration.
'session_storage' => [
   'type' => SessionArrayStorage::class 
],

After using above code still session expired within 5-10 minutes.I want session expired time more than 30 minutes.How to configure it in Zf3.

Please provide solution.

  • 写回答

1条回答 默认 最新

  • duanquan1876 2017-07-13 09:19
    关注

    You have the correct settings for the session manager, but this is not enough for these session settings to be used as the default one.

    My assumption is that you do not make this session manager your default one. In order to make it, you need to instantiate it as early as possible. One solution would be to do this is in module Module.php

    use Zend\Mvc\MvcEvent;
    use Zend\Session\SessionManager;
    
    class Module
    {
        //...
    
        /**
         * This method is called once the MVC bootstrapping is complete. 
         */
        public function onBootstrap(MvcEvent $event)
        {
            $application = $event->getApplication();
            $serviceManager = $application->getServiceManager();
    
            // The following line instantiates the SessionManager and automatically
            // makes the SessionManager the 'default' one.
            $sessionManager = $serviceManager->get(SessionManager::class);
        }
    }
    

    Reference

    EDIT: My 2nd assumption is that you use the global path for your sessions(eg /var/lib/php/sessions).

    In Debian, there is a cron that may clear sessions according to your php.ini session settings(/etc/cron.d/php).

    This cron uses your php.ini "gc_maxlifetime" and probably clears your sessions.

    To find out where your sessions are saved, use session_save_path(). Check that directory for your sessions.

    To overcome this, you should set "save_path" and this path should not be shared with others applications or scripts on your server(you do not want another script using the global gc settings or its own, deleting your sessions).

    Add

    'save_path'           =>   '/path/to/app/data/sessions'
    

    in your 'session_config' array.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值