简体   繁体   English

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

[英]Using of Session Database on multiple Apache Servers

I have been working on a webApp which should be able to perform tasks only by using AJAX. 我一直在研究webApp,它应该只能通过使用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. 它似乎工作得很好,但我遇到了一个问题,因为我没有在公共站点上存储Session变量。

My login procedure is similar to iCloud's. 我的登录程序类似于iCloud。 You arrive to one page asking for a login. 您到达一页要求登录。 Your login is sent to a server using AJAX and returns a true or false . 您的登录使用AJAX发送到服务器并返回truefalse If true, the login box disappears and you are ready to work with the applications. 如果为true,则登录框将消失,您已准备好使用应用程序。

在此输入图像描述

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. 当您查看上面的图像时,您将看到两个绿色框作为完全相同的站点,没有任何URL刷新或任何东西。 It is simply the same page. 它只是同一页面。

The Pink boxes represents Apache Servers that hasn't registered any Sessions . 粉红色框表示尚未注册任何Sessions Apache服务器。 My Session Class has been builded using the session_set_save_handler idea. 我的会话类已使用session_set_save_handler构思构建。

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. 我似乎无法找到公共站点在没有会话ID的情况下在pink服务器上请求数据的方法。 Could anybody tell me the idea behind the session_set_save_handler idea as if I was 6 years old? 有人能告诉我session_set_save_handler想法背后的想法,好像我6岁了吗? I have read the PHP manual for details, but it really confuses me. 我已经阅读了PHP手册了解详细信息,但它确实让我感到困惑。

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. 所有Apache服务器都通过LAN网络连接,并且能够进行通信。 Also they all have access to the same Session Class in an Apache include Library. 此外,他们都可以访问Apache include Library中的相同Session Class

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. 使用memcached,您可以为任何连接的服务器可以共享的所有会话数据提供中心点。

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. 如果您使用的是linux,下面的代码演示了如何注释掉本地文件会话处理,并用memcache替换它可以让您共享会话数据。

  ~$ 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 如需深入解释,请访问: http//bakery.cakephp.org/articles/rynop/2010/09/10/using-memcached-to-run-your-sessions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM