0

I have an object which is holding the state for specific user... I need this object to be aviable while the user in on one of the pages in my site.

My question is, where to save this object?

Database? => to many queries... To build the state object many queries needs to be performed... and the object must be rebuilt for each page...

SESSION? => read the object from the database and store it in $_SESSION. But each time the user swich page the object is serialized and deserialized... this affects the page loading time because the object serialization is heavy function....

COOKIE? => I need to access the state object from the server...

Is there any other option?

What is the common approach in this case?

Grigory Ilizirov
  • 1,030
  • 1
  • 8
  • 26
  • 1
    What's your problem with SESSION? – Thamilhan Jun 24 '16 at 11:16
  • i have a large object... and session save only text.... – Grigory Ilizirov Jun 24 '16 at 11:18
  • cant serialize it fast enough – Grigory Ilizirov Jun 24 '16 at 11:20
  • 3
    You can save an object/array in session then access it as if it was a regular variable. if you do `$_SESSION['user'] = $user_object`, you'll be able to access data like `$_SESSION['user']->name`. Of course, name can be any attribute you're trying to access. – trajchevska Jun 24 '16 at 11:27
  • Have you benchmarked serializing it? I find it hard to imagine that serializing / deserializing an object would take any significant time compared to all the other things involved in an http request... – jeroen Jun 24 '16 at 11:32

0 Answers0