简体   繁体   English

使用流量较高的$ _Session变量

[英]Using $_Session variables with high traffic

I am working on a quick survey for a company who will be getting about 200k (at peak) visitors hourly for about 2 days straight. 我正在为一家公司进行快速调查,该公司将连续2天每小时每小时获得200,000个(高峰)访客。 I was just wondering if using $_SESSION variables would tie up the server. 我只是想知道是否使用$ _SESSION变量会占用服务器。 All that we are storing in those variables are at most a 6 character string or a single digit integer. 我们存储在这些变量中的所有内容最多为6个字符串或一位整数。 I'm new to the PHP world so I'm not sure how reliable or how much $_Session variables will tie up the servers. 我是PHP世界的新手,所以我不确定服务器是否可靠或有多少$ _Session变量会占用服务器资源。 The servers we are using will be cloud servers. 我们正在使用的服务器将是云服务器。 One final note is that the the sessions will only last maybe 6 - 10 minutes tops for each visitor before I close it out. 最后要注意的是,在我关闭会议之前,每位访问者的会话最多只能持续6-10分钟。

Any help will be greatly appreciated! 任何帮助将不胜感激!

By default, data in $_SESSION will be written to disk upon each call to session_write_close(), or upon script termination. 默认情况下,每次调用session_write_close()或脚本终止时,$ _ SESSION中的数据都将写入磁盘。 There is no way to know for sure how this will perform without testing the final application on the server hardware you will be using. 如果不在要使用的服务器硬件上测试最终应用程序,就无法确定如何执行此操作。 Since the volume of data is small, the real worry is disk latency. 由于数据量很小,所以真正的担心是磁盘延迟。 An easy workaround for this would be to set PHP's session_save_path to an in-memory filesystem. 一个简单的解决方法是将PHP的session_save_path设置为内存文件系统。

Tie up how? 绑起来怎么样? Disk space? 磁盘空间? Storing a simple 6char string using the default file-based session handler will take up about 6+length-of-variable-name + ~6 chars of space on the disk. 使用默认的基于文件的会话处理程序存储一个简单的6char字符串将占用大约6+变量名长度+磁盘上约6个字符的空间。 There'll be some overhead to load/unserialize the data in the session file. 加载/反序列化会话文件中的数据会有一些开销。 but it'll be much less than the initial overhead of loading/compiling the script that's using the session data. 但它比加载/编译使用会话数据的脚本的初始开销要少得多。

Remember, PHP's default sessions use the disk as their storage media - they're not persisted in memory after the script exits. 请记住,PHP的默认会话使用磁盘作为其存储媒体-脚本退出后,它们不会保留在内存中。

In PHP you can change the session handler. 在PHP中,您可以更改会话处理程序。 The default session handler is to write data in a temp file, with one file per session. 默认的会话处理程序是将数据写入临时文件,每个会话一个文件。 It works okay, but has limitations when runnning high traffic apps (although with 200K/hour you shoudln't have problems with the default handler). 它可以正常运行,但是在运行高流量应用程序时有一些限制(尽管以200K /小时的速度运行时,默认处理程序应该没有问题)。

And easy solution is to use the session handler for Memcached, with the PECL/Memcache extension (not to confuse with the PECL/Memcached extension): 一个简单的解决方案是使用带有PECL / Memcache扩展名的Memcached会话处理程序(不要与PECL / Memcached扩展名混淆):

http://www.php.net/manual/en/memcache.examples-overview.php (see example #2) http://www.php.net/manual/en/memcache.examples-overview.php (请参阅示例#2)

I think you don't want to store data in sessions, because it writes to disk. 我认为您不想在会话中存储数据,因为它会将数据写入磁盘。 If someone hits the app with multiple requests, are you able to guarantee that they hit the same machine in the cloud? 如果有人通过多个请求访问该应用程序,您是否可以保证他们在云中访问同一台计算机? That's rather complicated to write. 编写起来相当复杂。 I would cookie the user instead. 我会用cookie代替用户。

http://php.about.com/od/learnphp/qt/session_cookie.htm http://php.about.com/od/learnphp/qt/session_cookie.htm

http://www.quora.com/Does-PHP-handle-sessions-by-writing-session-variable-data-to-disc-or-does-this-information-persist-only-in-RAM-Will-accessing-session-data-cause-a-disc-read-in-PHP http://www.quora.com/Does-PHP-handle-sessions-by-writing-session-variable-data-to-disc-or-does-this-information-persist-only-in-RAM-Will-访问会话数据的原因是光盘读取了PHP

Like the others said, I'd use Memcached if you want to scale, but to answer your question directly, I think your server should be able to handle the usage you describe. 就像其他人说的那样,如果您想扩展,我会使用Memcached,但是直接回答您的问题,我认为您的服务器应该能够处理您描述的用法。

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

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