2

I have no access to create/edit any databases but due to the massive amount of content I need some sort of management system which is why I created my own. Here's how it works:

Each blog post has got its own .php file which loads static parts of the website like the header or the menu bar. But there are many category sites that display previews of the respective posts. It would be sooo annoying having to edit the same preview on 10 sites due to a misspelled word or so. That's why I store those previews (not the full content since there's no need to) in a JSON file.

Is that bad practice? Could this lead to long loading times if the number of previews rose? And could I prevent that by creating multiple JSON files?

1

1 Answer 1

6

If you are working on a small scale, then using JSON files is fine however it would definitely be beneficial to switch to a database management system whenever possible for storage when it comes to PHP (Or the majority of languages for that matter).

It can be considered bad practice if JSON is used to store large amounts of data or if a lot of data is stored in the same file in which case yes, using multiple JSON files rather than one large one is indeed more viable since the input stream when reading the file does not have to go over as much data.

3
  • 3
    There's no "right answer" to the OPs question. I absolutely agree with everything you said. If he's asking "Q: Should I ALWAYS use a database, and NEVER consider disk files?", the answer is "Of course not! Disk files (e.g. Json files) are often appropriate, often PREFERABLE". But the OP failed to tell us 1) what's "huge", 2) why he CAN'T use a DB, 3) what different KINDS of DBs he "can't use", 4) how many files? 5) how they're identified? 6) Whether they're updated or write-once, 7) Etc etc etc. The OP needs to provide more info to get an informed answer :)
    – paulsm4
    Aug 13, 2020 at 0:18
  • Well, I'm sorry I can't tell you why I have no DB access but I have literally NO option to use ANY DB no matter which kind. "Huge" means: 3 previews (until now) = 40 lines (total) = 2 KB. There are properties that are overwritten, like clicks/views, likes, number of comments. Should I reduce the file size by "uglifying" my JSON (everything on 1 line, no unnecessary whitespace)?
    – Pixelcode
    Aug 13, 2020 at 12:22
  • 1
    SQLite is easy and robust these days: just one DLL and you can use any file as database. No installation, no users/permissions, no network/port issues, no text encoding limitations. Oh, and PHP supports it out of the box.
    – AmigoJack
    Jan 4, 2021 at 2:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.