Memory resident Object that survive a request?

Well this is a bit theoretical: I want to create an object once and use it in multiple requests, this is the short version.

The long version is: I have an object which loads a lot of data (some mega) into an array, now I realise that loading it on each request is a huge waste of time since the data does not change often. Is it possible to build an object which can be reused (without having to re-initialize it) for more than one request?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can use the serialize and unserialze function of php to store that object into a file

To store the object in the memory might be a littel more complicated. Have a look athe the shared memory extension of php (not available on Windows)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can also use sessions(overcomes read/write time), which by default serializes and unserializes data.

1. Register your class object using session_register(object)
2. Include your class file ex: in every php page.


This is one area where PHP differs from application servers like Tomcat, BEA.

PHP does not have application-wide global objects.

Sessions IS a way to simlate that, just remember then that this object will be copied once per each session. :-]
ie. 100 users = 100 sessions = 100 mb of the objects.

I am looking at this prob for some time and have decided to write some SHM-based global object manager; I will probably even put it somewhere under GNU license, but it is not there yet.
SnykeAuthor Commented:
As I see it, the option of storing the stuff in the session is just as good as loading the thing everytime, since sessions are itself stored in files...
The advantage of having it in an extra file is, that if you update that file all next request will have that updated object. If it's stored in the session, the old old version may last a long time...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.