Codeigniter session size limit
When storing the session in the database via
$config['sess_use_database'] = TRUE;
Is the size of the data limited to the size of the user_data field which is开发者_开发技巧 TEXT ... ? Not 4kb like a normal cookie.
To further clarify my comment above, when you elect to save the session data in a database, CodeIgniter doesn't set a cookie (other than the session id of course) but saves all of the information that it would have set in a cookie in your database.
If you have a look at the sess_write
in the Session
class located in ./system/libraries/
, if you have enabled the use of a database, you'll see that it serializes the data using serialize
and saves it directly to the database. There is no restriction on length imposed by CodeIgniter when saving to a database.
For your convenience, here's a link to the source code: https://bitbucket.org/ellislab/codeigniter/src/fe2247a927ab/system/libraries/Session.php#cl-252.
The only restriction is set by the field you chose to use to save the data in your database. For more information on the data type storage requirements of MySQL, read this.
I found the same "size limit" issue even i have ci_session
table for storing
I just change in data type of user_data = longtext
and my problem solve
although session size is limited to size of longtext NOT UNLIMITED
I guess this answer your question. from the class code:
// Are we saving custom data to the DB? If not, all we do is update the cookie
if ($this->sess_use_database === FALSE)
{
$this->_set_cookie();
return;
}
even the comments are from the class itself. so it updates the cookie IF not using the database.
The CI session docs specify a BLOB data column for your session data.
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(128) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
KEY `ci_sessions_timestamp` (`timestamp`)
);
According to the MySQL Docs this storage type requires L + 2 bytes, where L < 2^16. This means the BLOB (and therefore the serialized data in your session table) is limited to 65,535 bytes. NOTE that this limit applies to the length of your session data once it has been serialized which may cause some inflation relative to the amount of storage used in RAM.
You might, of course, choose a different data type when defining your session table. E.g., MEDIUMBLOB instead of blob would give you 16MB. This may or may not introduce performance issues.
精彩评论