//this is a trick I get when using Berkeley Database with PHP API
$db = new Db4();
$db->open(null, "/var/tmp/mydb.db", "mydb");
$lastid = $db->get("lastid");
$db->put("lastid", $lastid + 1);
$db->close();
When above code lines run at same time, something will may be wrong! We have to lock?
$fp = fopen("/var/tmp/lock-id", "w");
if (flock($fp, LOCK_EX)) {
... run above code
flock($fp, LOCK_UN);
} else {
// couldn't get the lock
// write log if you want
}
fclose();
Title:
Locking is easy
Description:
//this is a trick I get when using Berkeley Database with PHP API $db = new Db4(); $db->open(null, "/var/tmp/mydb.db", "my...
...
Rating:
4