Re: usage of flock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, March 23, 2007 10:34 pm, Myron Turner wrote:
>> You can do it with flock, but then you end up sooner or later with a
>> locked file from an "exit" or killed script, and then you have to
>> know
>> to remove locks older than X minutes.
>>
>> You could also just do a "mkdir" for your lock, and check its
>> filemtime.  You could even use "touch" within loop of the script to
>> make sure the script is still going, and safely assume that any lock
>> older than X seconds is stale and can be ignored/removed.
>>
> I've never used locks in PHP, but have used them in Perl.  In Perl a
> lock is automatically released on exit or when the locked file is
> closed.  Is that not the same in PHP?  According the the man page for
> the C version of flock, it too releases the lock on close and C's exit
> closes all streams.  So, Perl is consistent with that.  Just wondering
> for myself it this isn't the case with PHP, in case I ever  want to
> use
> a lock.

It is the case, just as in C or Perl, that it's SUPPOSED to shut down
nicely and remove the lock...

When, not if, when, something goes terribly wrong, and you manage to
segfault PHP/Apache, do you want to have to remember to manually nuke
the flock somehow, or do you just want to code it from the get-go to
ignore locks older than X time? :-)

No matter how carefully you program your locks, sooner or later,
you'll have to have some "meta" programming about the locks to deal
with an inconsistent state of locks.

At least, that's been my experience so far...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux