1

Would saving a large array in a PHP session be hard on the server? By "large" array, I mean an array that has perhaps 500 elements with each element having up to 100 fields.

I could have thousands of users doing this process several times / minute.

7
  • Yes, it would. What's in the array? You might be able to solve your problem with JavaScript-based localStorage. Commented May 14, 2013 at 17:41
  • I guess it may depends on whether you store your session data in files or in database... Commented May 14, 2013 at 17:42
  • It depends on your server configuration. Sessions are stored on the RAM and then HDD, and if you access them very often, it is inefficient .. use cookies, or a database .. Commented May 14, 2013 at 17:42
  • if the array is being used with every request the cost to deserialize it is probably less then to recreate it. If it's only used sometimes it would make more sense to find a different way to persist it Commented May 14, 2013 at 17:44
  • I would like to somehow store the array in memory as an auto-save feature before I write to XML on the server. The array is a bunch of objects that hold properties (like size, position, color, etc...). There could be hundreds or even thousands of objects each having up to 100 properties or so. Commented May 14, 2013 at 17:45

1 Answer 1

3

First, a brief intro to session handling in PHP:

When you open a session, a cookie is created that contains the ID of the session, and is sent to the client. PHP will then use the path defined in session.save_path to save a file using the id as filename ( reference ).

What does that mean in your case? It means you'll be creating an additional bottleneck (disk I/O is one of the slowest things in most setups) because you'll be writing/reading files all the time.

Database servers have tons of code to handle that kind of latency, so it might be very beneficial to just use a table in a database that has your serialized array as a string, keyed by an id in the $_SESSION.

Sign up to request clarification or add additional context in comments.

2 Comments

So you're suggesting to write to the database instead of the session? The sounds fine but I would have thought this would be even more of a concern for performance, no?
my actual suggestion would be to not request that much data in one go, but in all cases you should be requesting from a different mechanism than session. Database is the easiest, but you might want to checkout memcached or a similar in memory caching mechanism.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.