Skip to content

Instantly share code, notes, and snippets.

@FKasa
Created June 29, 2017 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FKasa/a93ec172a4008e267fa7cfb7e03a46e0 to your computer and use it in GitHub Desktop.
Save FKasa/a93ec172a4008e267fa7cfb7e03a46e0 to your computer and use it in GitHub Desktop.
PHP file database with collision prevention
$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