Posted by siliconmike on 10/22/05 03:58
pseudocode:
function generate_unique_id()
{
mkdir("lock");
if successful
{
$id = 10 digit random number;
make sure that $id does not exist in our table
if it does, generate a new one
insert $id into our table;
rmdir("lock");
}
else try mkdir again
}
do you see any race conditions?
this idea could be dangerous if the script died before rmdir("lock")..
any solution?
[I can't use auto-increment .. long story]
Mike
Navigation:
[Reply to this message]
|