17

I have a PHP form (mortgage app) that is about 400 fields, traffic on the site will be low.

What is the ideal Session size for 400 fields going into a MySQL db?

In php.ini what do I set?

Anything I should set that I am missing?

tereško
  • 58,060
  • 25
  • 98
  • 150

4 Answers4

17

There is no limit to the size of the session, BUT there is a limit to the memory PHP can take: http://ca.php.net/manual/en/ini.core.php#ini.memory-limit

Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
14

Well, personally I have had very large sessions before with very little problems. Probably the largest size I've had before is ~10MB. It's not optimal, but I haven't had a problem with slow scripts even with that size. I wouldn't worry about sessions getting to large, but I would try to keep it under control. My theory is, if keeping it in the session makes it much faster than quering the database every time (such as in the case of a search) then I go for it.

Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
11

It's not advisable to store a lot of data in a session. As others have noted, it's not a idea to duplicate data from a database. Even if you really need some sort of caching mechanism, you wouldn't store the data in a session. The problem is that PHP rewrites the session data for every request. And as we all know writing to disk is a rather slow operation.

If you really need to do it, serialize the array and store it in a separate file.

If you need that bunch of serialized data only 1 in 10 pages, you only unpack it once in 10 pages. Session is of course packing/unpacking for every request.

Rajib
  • 127
  • 1
  • 3
  • 5
    [source](http://bytes.com/topic/php/answers/11014-questions-size-session#post46656) – István Ujj-Mészáros Feb 10 '11 at 12:02
  • 1
    I don't think this is the correct answer. reading/writing data to database is also read/write to disk (except the memory cache). Also please note most games have to keep their data in memory for faster access which in case of PHP, it is session variables and database is only secondary idle storage. – AaA Mar 28 '15 at 02:58
2

You should also check, post_max_size, max_input_vars (1000 default so you are ok)

user824951
  • 71
  • 1
  • 3