php 会话变量有限制吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4274955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:30:07  来源:igfitidea点击:

Are there limits for session variables?

phpsession-variables

提问by jolt

As the title says, are there limits (if any) for session variables or they're considered as usualvariables and can store equal amount of data?

正如标题所说,会话变量是否有限制(如果有)或者它们被视为通常的变量并且可以存储等量的数据?

I'm looking if there are any other limits aside from variable type ones like max length, max values and so on.

我正在寻找除了诸如最大长度、最大值等变量类型的限制之外是否还有其他限制。

P.S. If the question is unclear, please let me know.

PS 如果问题不清楚,请告诉我。

Thanks in advance!

提前致谢!

采纳答案by Piskvor left the building

As @Thariama said, there's no limit on the number of variables; also, there's no limit on the amount of data you can store in a session (I've seen sessions tens of MB in size).

正如@Thariama 所说,变量数量没有限制;此外,您可以在会话中存储的数据量没有限制(我见过大小为数十 MB 的会话)。

As the size of a session gets larger, you'll run into various quirks though: PHP 5 deserializes the whole session into memory at session_start()(using the default session handler - you can make you own solution, of course); with a 20 MB session and 50 concurrent users, your scripts start to be severely limited by disk access speeds (a.k.a. "script startup is slow as molasses" - the sessions alone would be hogging a GB of RAM); in the end, we dedicated a box to keep as many sessions as possible in its RAM, and the frontend boxes accessed them over NFS (although it helped in our case, this may be overkill for you).

随着会话的大小变大,您会遇到各种怪癖:PHP 5 将整个会话反序列化到内存中session_start()(使用默认会话处理程序 -当然,您可以创建自己的解决方案);对于 20 MB 的会话和 50 个并发用户,您的脚本开始受到磁盘访问速度的严重限制(又名“脚本启动速度像糖蜜一样慢”——仅会话一项就会占用 1 GB 的 RAM);最后,我们专门使用了一个盒子来在其 RAM 中保留尽可能多的会话,并且前端盒子通过 NFS 访问它们(尽管它在我们的案例中有所帮助,但这对您来说可能有点过头了)。

Note that for many concurrent users and session storage on disk, the number of session temporary files may cause problems with filesystem limits (e.g. how many files can be in one directory before you run into problems with stat()performance), or other limits (we once found the hard way that a box was configured to only allow 4096 open files at the same time). None of this is really session-specific, but can be triggered by session handling.

请注意,对于磁盘上的许多并发用户和会话存储,会话临时文件的数量可能会导致文件系统限制(例如,在遇到stat()性能问题之前一个目录中可以有多少文件)或其他限制(我们曾经发现一个盒子被配置为只允许同时打开 4096 个文件的硬方法)。这些都不是真正特定于会话的,但可以由会话处理触发。

回答by Thariama

No, there is no limit on much space a session may have (or how many variables a session may possess). The only limit is the specs on your computer, this is defined by your available memory_limit in your php.ini . Be aware that this space will be shared among all sessions for all users.

不,会话可能拥有的空间(或会话可能拥有的变量数量)没有限制。唯一的限制是您计算机上的规格,这由您的 php.ini 中的可用 memory_limit 定义。请注意,此空间将在所有用户的所有会话之间共享。

回答by shamittomar

It is completely specific to your web-server. For Apache, look here:

它完全特定于您的网络服务器。对于 Apache,请看这里:

http://httpd.apache.org/docs/trunk/mod/mod_session.html

http://httpd.apache.org/docs/trunk/mod/mod_session.html

It even allows sessions to be stored in databaseby using mod_session_dbd. Therefore physical limits like 1 file per session can be overcome. Moreover, Apache can be configured to keep track of per user sessions stored on a particular server or group of servers for scalability.

它甚至允许使用mod_session_dbd将会话存储在数据库中。因此可以克服物理限制,例如每个会话 1 个文件。此外,Apache 可以配置为跟踪存储在特定服务器或服务器组上的每个用户会话,以实现可扩展性。

回答by Matthew

The simple answer is no. (That is, they have no more restrictions than any other PHP variable has... must fit into memory, etc.)

简单回答是不。(也就是说,它们没有比任何其他 PHP 变量更多的限制......必须适合内存等。)

However, keep in mind that $_SESSIONdata is stored somewhere, by default as serialized data in one file per session. So there are practical limitations. You wouldn't want to store a huge blob of information in them because they would be loaded/saved from the data store on every page that uses session_start().

但是,请记住,$_SESSION数据存储在某处,默认情况下作为每个会话一个文件中的序列化数据。因此存在实际限制。您不希望在其中存储大量信息,因为它们会在每个使用session_start().