Created
June 29, 2017 08:19
-
-
Save FKasa/a93ec172a4008e267fa7cfb7e03a46e0 to your computer and use it in GitHub Desktop.
PHP file database with collision prevention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$myfile=fopen('json_holder.txt','rt'); | |
flock($myfile,LOCK_SH); | |
$debnr = json_decode( file_get_contents('json_holder.txt') ); | |
@$min = (int)reset(array_keys((array)$debnr, min((array)$debnr))); | |
$debnr->$min++; | |
fclose($myfile); | |
file_put_contents('json_holder.txt', json_encode($debnr,JSON_FORCE_OBJECT), LOCK_EX); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment