简体   繁体   中英

PHP Settings / Config File For Variables?

I'm currently working on a script for our linux hosting company. We need to store variables such as versions and last update checks in a config.ini file which needs to be accessed and written to according to any updates made by the updater script.

I really need help writing the variables to a config.ini file (and later overwriting or changing the variables when they are updated), creating the config.ini file and reading the variables from the config.ini file.

The variables get stored at different times and not all at once, so one array won't work. I also have if statements, so some variables will be put in the file in certain situations and in other situations, there will be different variables in the file.

Example:

Server1 has game1 installed. Server2 has game2 installed.

Script checks for game1, then checks database for latest version, compares with the config file. If config file is blank or old, updates and then changes config file version to database version. Repeats again for each game. If the game is not there, no variables stored and skip to the next step.

I'm battling a lot with trying to read and write to the file at separate intervals without overwriting the previous lines.

Would be awesome to get some support.

Regards, Skowt

I guess you want ideas. Try using yaml, xml, sqlitedb to store your config settings. XML might be bit hard since you have to read and write. To me yaml files seems like a good options. I haven't tried PHP yaml function yet, symfony has a good yaml component.

Another options as I mentioned is to use a sqlitedb might come in handy if you have a lot of complicated configs.

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