1

How to save a variable at application level(same for all users) in php which will get updated after some time?

I've tried to find about it. I've found the following solutions:

  1. Implement using file handling.
  2. Cache (Memcache or APC)
  3. Implement using Database Support

2 is considered as best (AFAIK). (I'm not allowed to install anything on the Server)

What about other two (mentioned above) or any other options and how I can implement those? I'm bit concerned because traffic is moderately high (but the bad thing is that I still can't use any cache mechanism). We just need to save the contents of buffer of around 255 bytes at application level.

Any snippets, pointers or help of any sort would be highly appreciated.

Thanks.

1
  • Define "high traffic" please. Commented Nov 29, 2010 at 9:47

4 Answers 4

2

You need a permanent storage, not cache or something like that. If your application doesn't use a database already, there are several options you can choose from:

  • write to a text file, a simple one line entry or preferably in a format like xml, json
  • write to a light storage engine like sqlite, simple storage (Amazon S3)

If your app uses a database already, why not store that data in a separate table?

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

2 Comments

Thanks Guys for quick help. I'm really concerned about the speed. I just want the saving and retrieval of information very quick. Another concern is there are going to be lots of requests per second (probably multiple requests at the same time) so can you guys recommend the best proctices how to achieve this. Actually token needs to be updated after N minutes (where N = Random) and only when a request comes in. So, I need to write the logic in the file that is being requested (which is only one single file).
BTW let me tell you the problem once again probably you would be able to contribute some more ideas - I need to return the same token (application wide which will be retrieved from Database) to all users for N random minutes (Value of N depends upon token). After N minutes token has to be replaced with the some random token (for next M minutes). The requirement is to make sure that all the users share same token at a time (obviously for all the requests made in that time frame).
2

This is what databases are for. If you don't want to spend a lot of time setting up a large database application, try out sqlite.

Comments

1

Some caches (memcache in particular) are lossy, and most won't survive being restarted. Use a database.

Comments

0

If you do not have the option to use databases you can consider writing the data to a file on disk.

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.