简体   繁体   中英

Should I store application-scope variable inside a file in PHP?

I want store a variable shared between sessions (application-scope):

  1. It is not user session-specific (so I can't put it in $_SESSION[]).
  2. It is a long term storage (so I can't use APC - Alternative PHP Cache).

So, I use a file do store the variable and access it using file_get_contents and file_put_contents functions.

Is it a good way of proceeding or is there any alternative?

It's clear your's is a global, server side issue. I would use a Database to do it. Just CRUD when needed.

You'rs may do the work, but I recommend the database approach, due to the enhanced capabilities that it provides like logging, checking the history of events. I think is a cleaner solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM