Important database session limitation

If you are using a database to keep your sessions, there is one rather significant limitation which you should be aware of.

It does depend on the specifics of your DB, but I am going to guess that in most cases it is something that could happen to any database…

For example, we were using MySQL to keep the session data.
Looking at the table you’ll see that session data is serialized and stored in the “data” field…

By default that field is set to MySQL’s “TEXT” type, which has a size limitation of ~ 65K.

I know, I know… why would you want sessions larger than 65K?

“640k ought to be enough for anybody”

So, just in case, you do need a larger session the remedy is pretty simple, change the field type to “MEDIUMTEXT”, which effectively gives you ~ 16MB.

p.s. If you need even a larger size you can go with “LONGTEXT”.

For your reference, here’s the semi-official breakdown of different text-type fields in MySQL and their limitations:

A BLOB or TEXT column with a maximum length of 65535 (2^16 – 1) characters

A BLOB or TEXT column with a maximum length of 16777215 (2^24 – 1) characters

A BLOB or TEXT column with a maximum length of 4294967295 (2^32 – 1) characters

Sharing CakePHP session with another app

This question pops up once in a while: “How do I share session data with a third-party application?”

Thankfully the answer is pretty simple, just make sure that the session (cookie) name is the same for both apps.
In CakePHP it’s set in the core.php… Configure::write(‘Session.cookie’, ‘CAKEPHP’);