Re: usage of flock

From: Date: Tue, 27 Mar 2007 15:04:38 +0000
Subject: Re: usage of flock
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-251458@lists.php.net to get a copy of this message
Richard Lynch wrote:
On Fri, March 23, 2007 10:34 pm, Myron Turner wrote:
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... It is something to think about. I've never had this problem but possibly because the sites haven't been high traffic enough.
Thanks, Myron

« previous php.general (#251458) next »