设为首页 收藏本站
查看: 640|回复: 0

[经验分享] Lvs环境下的zendframework session问题

[复制链接]

尚未签到

发表于 2019-1-3 13:22:25 | 显示全部楼层 |阅读模式
  Lvs环境下的zendframework  session问题,已经采用了nfs共享存储但是zendframework框架的session被分散到每台机器上去了,导致session问题,解决办法:
The success of the web is deeply rooted in the protocol that drives the web: HTTP. HTTP over TCP is by its very nature stateless, which means that inherently the web is also stateless. While this very aspect is one of the dominating factors for why the web has become such a popular medium, it also causes an interesting problem for developers that want to use the web as an application platform.
The act of interacting with a web application is typically defined by the sum of all requests sent to a web server. Since there can be many consumers being served simultaneously, the application must decide which requests belong to which consumer. These requests are typically known as a "session".
In PHP, the session problem is solved by the session extension which utilizes some state tracking, typically cookies, and some form of local storage which is exposed via the $_SESSION superglobal. In Zend Framework, the component Zend_Session adds value to the PHP session extension making it easier to use and depend on inside object-oriented applications.
Basic Usage of Zend_Session

The Zend_Session component is both a session manager as well as an API for storing data into a session object for long-term persistence. The Zend_Session API is for managing the options and behavior of a session, like options, starting and stopping a session, whereas Zend_Session_Namespace is the actual object used to store data.
While its generally good practice to start a session inside a bootstrap process, this is generally not necessary as all sessions will be automatically started upon the first creation of a Zend_Session_Namespace object.
Zend_Application is capable of configuring Zend_Session for you as part of the Zend_Application_Resource system. To use this, assuming your project uses Zend_Application to bootstrap, you would add the following code to your application.ini file:

  • resources.session.save_path = APPLICATION_PATH "/../data/session"
  • resources.session.use_only_cookies = true
  • resources.session.remember_me_seconds = 864000



As you can see, the options passed in are the same options that you'd expect to find in the ext/session extension in PHP. Those options setup the path to the session files where data will be stored within the project. Since INI files can additionally use constants, the above will use the APPLICATION_PATH constant and relatively point to a data session directory.
Most Zend Framework components that use sessions need nothing more to use Zend_Session. At this point, you an either use a component that consumes Zend_Session, or start storing your own data inside a session with Zend_Session_Namespace.
Zend_Session_Namespace is a simple class that proxies data via an easy to use API into the Zend_Session managed $_SESSION superglobal. The reason it is called Zend_Session_Namespace is that it effectively namespaces the data inside $_SESSION, thus allowing multiple components and objects to safely store and retrieve data. In the following code, we'll explore how to build a simple session incrementing counter, starting at 1000 and resetting itself after 1999.

  • $mysession = new Zend_Session_Namespace('mysession');

  • if (!isset($mysession->counter)) {
  •     $mysession->counter = 1000;
  • } else {
  •     $mysession->counter++;
  • }

  • if ($mysession->counter > 1999) {
  •     unset($mysession->counter);
  • }



As you can see above, the session namespace object uses the magic __get, __set, __isset, and __unset to allow you to seamlessly and fluently interact with the session. The information stored in the above example is stored at $_SESSION['mysession']['counter'].

Advanced Usage of Zend_Session

Additionally, if you wanted to use the DbTable save handler for Zend_Session, you'd add the following code to your application.ini:

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




  参见:http://framework.zend.com/manual/zh/learning.multiuser.sessions.html




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-659023-1-1.html 上篇帖子: lvs安装及基本语法介绍 下篇帖子: 【LVS】负载均衡集群
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表