PHP 会话与 Share-Nothing-Architecture 冲突吗?
当我第一次接触 PHP 时,我对“无共享架构”这个想法感到惊讶。我曾经参与过一个项目,其可扩展性因在不同 HTTP 请求之间共享数据而受到影响。
然而,当我继续我的 PHP 学习时。我发现PHP有会话。这看起来与不共享任何内容的想法相冲突。
那么,PHP session只是为了做ASP/ASP.NET/J2EE的对应技术而发明的吗?高可扩展性网站应该使用 PHP 会话吗?
When I first meet PHP, I'm amazed by the idea Sharing-Nothing-Architecture. I once in a project whose scalaiblity suffers from sharing data among different HTTP requests.
However, as I proceed my PHP learning. I found that PHP has sessions. This looks conflict with the idea of sharing nothing.
So, PHP session is just invented to make counterpart technology of ASP/ASP.NET/J2EE? Should high scalable web sites use PHP session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认 PHP 模型会基于每个用户锁定会话。这意味着,如果用户 A 正在加载页面 1 和 2,而用户 B 正在加载页面 3,则唯一会发生的延迟是页面 2 必须等到页面 1 完成 - 页面 3 仍将独立于页面 1 加载2 因为没有任何内容可供单独的用户共享;仅在给定会话内。
所以这基本上是一个一半对一半的解决方案,最终效果还不错——大多数用户不会同时加载多个页面;因此会话锁定延迟通常很低。就不同用户的请求而言,仍然没有任何共享。
The default PHP model locks sessions on a per-user basis. That means that if user A is loading pages 1 and 2, and user B is loading page 3, the only delay that will occur is that page 2 will have to wait until page 1 is done - page 3 will still load independently of pages 1 and 2 because there is nothing shared for separate users; only within a given session.
So it's basically a half-and-half solution that works out okay in the end - most users aren't loading multiple pages simultaneously; thus session lock delays are typically low. As far as requests from different users are concerned, there's still nothing shared.
PHP 允许您编写自己的会话处理程序 - 因此您可以使用默认挂钩构建您自己的语义 - 或者,如果您愿意,您可以使用内置功能来生成会话 id 并处理浏览器端的事情,然后编写您自己的代码来存储/获取会话数据(例如,如果您只希望登录页面而不是其他页面在处理过程中锁定会话数据,那么这有点棘手,但使用标准挂钩并非不可能)。
我对 Microsoft 会话处理架构了解不够,无法对此发表评论,但与 J2EE 相比,PHP 会话处理方式以及会话中实际存储的内容存在巨大差异。
在大多数页面中不使用会话将使应用程序执行速度更快,并且可能更容易扩展 - 但您可以这样说应用程序使用的任何数据。
C.
PHP allows you to write your own session handler - so you can build in your own semantics using the default hooks - or, if you prefer you could use the built in functionality to generate the session id and deal with the browser side of things then write your own code to store/fetch the session data (e.g. if you only wanted the login page and not other pages to lock the session data during processing, then this is a bit tricky though not impossible using the standard hooks).
I don't know enough about the Microsoft architecture for session handling to comment on that, but there's a huge difference in the way that PHPs session handling, and what actually gets stored in the session compared with J2EE.
Not using sessions in most of your pages will make the application tend to perform a lot faster and potentially scale more easily - but you could say that about any data used by the application.
C.