3

I've created a test file to find out how big my session can be.

It's something like this:

print_r($_SESSION);
$test = array();

for ($i=0;$i<3320;$i++) {
    $test[$i] = "test:)";
}

$size = mb_strlen(serialize($test), '8bit');

echo "Size: $size";

$_SESSION['test'] = $test;

When I do this, the $_SESSION['test'] gets reset (its value is nothing). When I'm doing this in a lesser for (3319 times) or for a shorter string, then it's working fine. Size value is in this case 65279 bytes. I figure I should be able to change some setting in php.ini to be able to store more data, but which one would that be?

Just for your information - I don't care about performance, there shouldn't be really more than one person at the time using the script and it's for some synchronization with another server so the user will need to wait anyway. I'm just looking for an information how can I store more data in the $_SESSION table.

My PHP version is 5.2.17 and I'm using osCommerce (really old one).

Kelu Thatsall
  • 2,494
  • 1
  • 22
  • 50
  • There shouldn't be a size limit for session variables (although this sounds like there might be a 64k[-ish] limit in play here). Do you have a PHP extension like Suhosin active that might impose such limitations? – Pekka Jan 28 '14 at 12:43
  • I don't have this Suhosin you are talking about but I don't know if any of my extensions wouldn't be capable to impose those limitations. This site is using an old osCommerce, maybe that's the case here. – Kelu Thatsall Jan 28 '14 at 12:45
  • Hmm, sounds unlikely. – Pekka Jan 28 '14 at 12:58
  • Why? I just tested it out without using osCommerce built-in session functions and it seems that was the case. Now I need to find in this shitty code where is the lock for the size. – Kelu Thatsall Jan 28 '14 at 13:02
  • Oh, so you used osCommerce's session wrapper for this and not native PHP as your code indicates? That changes the game, of course. (Please do remember to mention stuff like that from the start next time, to prevent people from wasting a lot of time in the wrong direction.) – Pekka Jan 28 '14 at 13:04
  • Yeah, I know I should've mentioned it but my code just looked like I described it, I created a wrapper for it and forgot about that it loads automatically. – Kelu Thatsall Jan 28 '14 at 13:10
  • Yeah, that happens. The problem seems to be ancient: http://www.oscmax.com/forums/oscmax-v1-7-discussion/3314-increasing-session-variable-sizes.html Could be some unintended side effect of a sanitation function or something – Pekka Jan 28 '14 at 13:15
  • Yes it ancient ;) The site was created like 10 years ago and not updated with newer versions since then. – Kelu Thatsall Jan 28 '14 at 13:51
  • 1
    And I found the solution - it was pretty straightforward. Sessions were stored in the database and the field to store the values was set to `Text` (its limit is 65,535 bytes ). – Kelu Thatsall Jan 28 '14 at 13:53
  • Cool; why not add that as an answer (and edit the OScommerce term into the question) – Pekka Jan 28 '14 at 17:10
  • PHP 5.x.x was loading the whole session into memory at session_start(); with a 20 MB session and 50 concurrent users, regards! – Ing. Alejandro Kohen Jan 28 '14 at 12:46

2 Answers2

1

Sorry for misguiding guys. It seems the reason for that was that I was storing the session in database (using osCommerce). Database field which holds the value of session was set to be of type Text which is 64KB. I've changed it to Mediumtext (16MB). If someone needs even more data in their sessions they might want to use Longtext (4GB).

Kelu Thatsall
  • 2,494
  • 1
  • 22
  • 50
0

You cannot set size to a session in php. you can, however, set the memory limit [I advise you to be careful with limitations in code if doing this].

http://ca.php.net/manual/en/ini.core.php#ini.memory-limit

Mutale
  • 310
  • 1
  • 8