Posted: Mon Dec 06, 2004 12:35 pm
no, flock doesnt suck, you just need to understand how to use it correctly.
depending on the os and other things though,
it might not be guaranteed flock will work as you expect though.
some php versions have small bugs, that may or may not affect what your trying to do.
check the bug reports for your version
you cannot use lock "files" because making, deleting,
checking for existance etc of a file is not an atomic operation,
so you still have a race condition which is prone to failing.
making a directory IS an atomic operation on most o/s though,
so you can make a lock dir and use it safely
this is why i wrote the function that i did,
and i have not seen it fail yet. i really think its a good solutuion to some situations.
my function opens the file in append mode,
but you can modify it to your needs.
but if your host does not have your files locally on the same server,
mkdir is not atomic and will
have a race condition just like files, and wont work.
i think semaphores would be a better solution, but i dont understand them enough to feel comfortable using them.
depending on the os and other things though,
it might not be guaranteed flock will work as you expect though.
some php versions have small bugs, that may or may not affect what your trying to do.
check the bug reports for your version
you cannot use lock "files" because making, deleting,
checking for existance etc of a file is not an atomic operation,
so you still have a race condition which is prone to failing.
making a directory IS an atomic operation on most o/s though,
so you can make a lock dir and use it safely
this is why i wrote the function that i did,
and i have not seen it fail yet. i really think its a good solutuion to some situations.
my function opens the file in append mode,
but you can modify it to your needs.
but if your host does not have your files locally on the same server,
mkdir is not atomic and will
have a race condition just like files, and wont work.
i think semaphores would be a better solution, but i dont understand them enough to feel comfortable using them.