Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a maximum number of PHP sessions?

Tags:

php

session

Simple question: Is there a limit to the number of concurrent PHP sessions? If a site were to have 1000+ people logged in at the same time, would sessions still be the accepted way to store the variables, or would a different method be used?

I presume it would be determined by the server rather than the PHP itself(?), so not only the number of sessions but also the size of each session would make a difference, but im not sure!

like image 312
Giovanni Avatar asked Feb 23 '14 18:02

Giovanni


People also ask

How many sessions can PHP handle?

PHP sessions are (by default) file based, so you can have as many of them as can fit on your server's disk. Save this answer. Show activity on this post. No, this exactly means that there can't be more than 30 simultaneous connections.

What will happen if the maximum number of sessions are reached?

"The maximum number of concurrent sessions has been reached." This indicates that all of your account session channels are in use. This can happen if somebody else is using your Mikogo account to host a meeting. It can also happen if a session is left open after switching presenter.

How much data session can store?

Session storage can store data ranging between 5mb - 10mb. The exact amount of storage capacity varies as per each browser's implementation, but it's a lot more than 4kb of storage capacity cookies offer!

What is PHP session lifetime?

gc_maxlifetime - defines the number of seconds after which the session data at the server are considered "garbage". The default value for session. gc_maxlifetime is 1440.


1 Answers

Off the top of my head, there should be several limits:

  • The random id generated for each session is of a fixed length, ergo there are only a limited number of random ids available. (I don't know whether PHP will increase the length of the id if it exhausts the number of available ones, I don't think so.) But, that number is ridiculously large, and will likely by far exceed the
  • number of files which can be stored in a single directory, which is limited by the filesystem. Since all sessions are stored as files by default in a single directory, you'll reach this eventually.
  • The size of the disk on which the session data is stored.

I don't think there are any other hard limits on the number of sessions. However, all these factors are much larger than 1000. 1000+ sessions can still be perfectly handled by standard PHP file based sessions. If you notice that is getting a problem, you can exchange the session backend easily. There are pluggable session handlers for memcached or other memory or database based storage systems. You can easily write your own sessions handlers to do whatever you want in any scalable form you need. You can still keep using the standard PHP session functions in your code.

like image 181
deceze Avatar answered Nov 05 '22 07:11

deceze