duanfaxin7014 2013-04-23 11:40
浏览 106
已采纳

在多个Apache服务器上使用会话数据库

I have been working on a webApp which should be able to perform tasks only by using AJAX. It seems to work pretty good, but I am running into a problem, because I do not store Session variables on the public site.

My login procedure is similar to iCloud's. You arrive to one page asking for a login. Your login is sent to a server using AJAX and returns a true or false. If true, the login box disappears and you are ready to work with the applications.

enter image description here

When you Are looking at the image above, you shall see the two green boxes as the exact same site, without any URL refreshes or anything. It is simply the same page.

The Pink boxes represents Apache Servers that hasn't registered any Sessions. My Session Class has been builded using the session_set_save_handler idea.

session_set_save_handler(
         array($this, 'open'),
         array($this, 'close'),
         array($this, 'read'),
         array($this, 'write'),
         array($this, 'destroy'),
         array($this, 'gc')
     );

I can't seem to figure out a way for the public site to ask for data on the pink servers without a Session ID. Could anybody tell me the idea behind the session_set_save_handler idea as if I was 6 years old? I have read the PHP manual for details, but it really confuses me.

If anybody knows about how this communication method could work properly, please tell me. All of the Apache Servers are connected through a LAN network, and are able to communicate. Also they all have access to the same Session Class in an Apache include Library.

  • 写回答

1条回答 默认 最新

  • dtpoius74857 2013-09-04 14:31
    关注

    It appears the problem you are having can be solved using distributed sessions.

    Using memcached you can provide a central point for all session data that any connected server can share.

    If you are using linux, the below code demonstrates how commenting out local file session handling, and replacing it with memcache can allow you to share session data.

      ~$ cat /etc/php5/apache2/php.ini | grep -i session 
      [Session] 
      ;session.save_handler = files 
      session.save_handler = memcache 
      session.save_path = "tcp://127.0.0.1:11211"
    

    For an in depth explanation visit: http://bakery.cakephp.org/articles/rynop/2010/09/10/using-memcached-to-run-your-sessions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题