php executes multiple files simultaniously?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Still not clear whether flock() works. I'd be fine we narrowed it to Linux. The method shown does not use flock() but instead relies on mkdir().
Post Reply