Humble Learner
Humble Learner

Reputation: 821

How to save a variable at application level in php?

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.

Upvotes: 1

Views: 2371

Answers (4)

markus
markus

Reputation: 40675

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?

Upvotes: 2

Yeroon
Yeroon

Reputation: 3243

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

Upvotes: 0

Greg
Greg

Reputation: 21899

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.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

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

Upvotes: 1

Related Questions