Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save website settings in Database vs File(.json)

I'm developing a website, and for the settings and preferences like website language, ads layout, some template string messages for emails, etc, I decided to use a Json file instead of saving to database. Now is there any reason why I shouldn't use a json file and stick to database?

PS. I'm using Zend Framework 2 and I'll definitely set the correct permissions on the json file(644 maybe).

PSS. This is not a duplicate of JSON vs DATABASE. I don't think that I will be storing sensitive data in the json file.

Thank y'll.

EDIT: YES, I know that I'll be saving to a file, but I wanted to be more specific. I'll be saving to settings.json. A JSON FILE!

like image 453
Milad.Nozari Avatar asked Feb 15 '23 23:02

Milad.Nozari


1 Answers

The answer is yes, there are reasons against using a File (whatever the format). If they are enough to switch to a database, that's for you to decide.

I can think of:

  • you will be parsing the file on every request, unless you save the json object in a php cache
  • you need to be very careful with permissions: 644 will make the file readable by everyone, you probably want 640 and the file owned by the sysadmin user and the webserver group.
  • a file based system is hard to scale and query: if you ever add a new server to the system, you need to keep the files in sync or on a separate/shared filesystem, which creates a bottleneck for the application; you also lose the ability to search the contents with the convenient SQL interface of your database.

The points can probably summarized with: if you expect to grow your application to something that needs to scale, use a database. If you aren't, use whatever fits.

like image 61
mabi Avatar answered Feb 24 '23 19:02

mabi