1

I need to hold a semi-static large object in cache so I don't need to request it every time from database. Something like $_SESSION, but not tied to a session, because the data are common to all users. I can cache client side that data, once I got it, but I would like to avoid disturbing the database with select queries of large data that (almost) never changes.

Also, I cannot add modules (like APC cache) in this environment.

I could store my data into a file, say a JSON, which I read with php instead of querying db, but accessing filesystem is also disturbing if php needs to do it many times per seconds AND filesize is not tiny.

Is there a built in way in php to store objects in memory, common to all php instances?

EDIT: Could I use $_session as storing space, forcing session_id to be always the same? Is it dangerous? I don't use sessions for the application itself. I tried and it works

3
  • Define "semi large" in terms of real-world units like bytes. PHP does not really have shared memory, and even if it did that's a really rough solution to this problem. Commented Aug 17, 2017 at 16:43
  • 2
    Have you thought about using Redis? You can use the PHP client called Predis. Pretty easy Commented Aug 17, 2017 at 16:43
  • Semi large means here 5MBytes, but it could become soon 15MB Commented Aug 17, 2017 at 16:55

1 Answer 1

1

Most Operating systems will store the result of reading from disk in its cache.

This means that the disk will not be hit each time. File based storage is actually pretty quick for multiple reads of the same file as its really just coming direct from memory.

as long as "pretty large" still means fits in memory this way should be fine

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

3 Comments

What about using this on a shared server, like Altervista? Wouldn't disk cache be flushed too often?
it was a good question and answer... I wish you would like to give us a reference. I really like the question and the answer and I'm wonder why nobody upvote it and after 5 years I'm the first person who upvote it
ref is linuxatemyram.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.