0

I want to create a PHP variable that is filled from the data of DataBase. I want to avoid the query to the database every request since it content is constant over every week, so it is not completly constant. Maybe there are some kind of variables, like $_SESSION, but that retain it content for every request and every user.

What strategy would you recommend?

Thanks a lot.

5
  • What is the value? Why does it change? Could you not store it in a cookie that expires weekly? Commented Aug 14, 2014 at 8:10
  • 1
    Is this a long, slow query? If not, then why worry about it! If it is, then look at caching options like redis or memcache or even APCu Commented Aug 14, 2014 at 8:10
  • It is used on webservices, so I cannot use cookies. And yes it is a long and slow query. What are reds or memcache useful for? Commented Aug 14, 2014 at 8:11
  • What do you consider to be a slow query? Why not optimize the query instead? Commented Aug 14, 2014 at 8:12
  • Key/value stores like Redis, Memcache or APCu are useful for storing data for quick retrieval by key, which makes them very good for caching Commented Aug 14, 2014 at 8:14

1 Answer 1

1

On the PHP side you could use Memcache (or Memcached) to store variables in the server memory and use that to avoid frequent trips to the database for the same data.

On the database side, there may also be caching options that least alleviate the load on the DB server if it needs to respond to the same query and data has not changed. In MySQL, this is called the Query Cache, but other database might have similar variations.

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

Comments

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.