gventuri / simple-json-db

A simple json db class written in php
10 stars 5 forks source link

Concurrency #4

Open raygit83 opened 6 months ago

raygit83 commented 6 months ago

How is this implementation supposed to handle concurrent accesses?

The only time the db file is read is during the constructor, so whenever two or more clients instanciate the class at roughly the same time, all edits performed by the other clients will be overwritten by the one who commits their changes the last.

Is this intended behavior? Imho the json file must be reloaded/parsed and merged with db's contents in locked fashion before every write that's being performed. Otherwise you'll quickly lose changes when multiple clients access the same db file.

Please clarify. Thanks.

MacSass commented 4 months ago

I think that is a valid comment, that the nice and small DB here does not really handle currently, right? Maybe some "locking" could be implemented to prevent that?