user2048702
user2048702

Reputation: 11

Using file with json data as database

I'm writing a small program that does just one task, stores phone numbers that need to be returned, And my goal is to use a single Json file as the database. Now here is my problem, since I want all employees to have access to this program I can't use PHP's json_decode and _encode functions and then use fwrite() because then one employee will be overriding another. So my question is if their is any workaround for this or if someone can suggest a library that would handle this. Any help is appreciated.

Upvotes: 0

Views: 201

Answers (1)

quickshiftin
quickshiftin

Reputation: 69581

You can handle this by creating a mutex. If you're on Windows, I'd suggest flock, but if you're on *nix, I'd suggest a sys5 semaphore.

As an aside, if you want a much hackier/simpler setup, you can pump the output from json_encode through error_log, as it implements its own mutex.

Another option which is probably easier would be to use SQLite.

Upvotes: 1

Related Questions