0

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.

8
  • Do you know about mongodb ? This should perfectly fit your needs Commented Feb 6, 2013 at 22:33
  • @hek2mgl yes but I'm doing this for fun too, so I'm playing around a little Commented Feb 6, 2013 at 22:34
  • 2
    If you must store everything in a single file, you'll have to use some locking mechanism to ensure two people are not editing / writing concurrently. Commented Feb 6, 2013 at 22:36
  • 1
    Why not use sqlite? It's a database in a file Commented Feb 6, 2013 at 22:37
  • 2
    this is not software engineering..this is just a bad way to use tools in the way they are not born/made for. So as people yet suggested to you, use sqlite or mongodb or even better just share a document with this numbers (like google docs..) Commented Feb 6, 2013 at 22:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.