Re: Re: Mandatory File Locking in PHP?

From: Date: Thu, 30 Jan 2003 17:10:43 +0000
Subject: Re: Re: Mandatory File Locking in PHP?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-93806@lists.php.net to get a copy of this message
On Thursday, January 30, 2003, at 04:28 AM, Ananth Kesari wrote:
So, as of now, do we restrict PHP script to use only advisory file locking?
Mandatory locking is an OS thing, not a PHP userspace thing. Given appropriate mount options on your fs (certainly out of the scope of php's responsibility), and appropriate permissions on the file (doable from within php of course, but seems odd to have to internally check and chmod a file as part of a locking procedure), then fcntl locks will be mandatory. Assuming that your filesystem is mounted -o mand, you can just do this: function mandatoryLock($file) { // go through the arcane dance of setting g+s, g-x $mode = (stat($file)[2)]; $mode = $mode ^ 0010; $mode = $mode | 02000;
         chmod($file, $mode);
// lock it
         $fp = open($file, "a+");
         flock($fp,  LOCK_EX);
} The point I'm trying to make, is that you can already set up your system so that you can do mandatory locks from within php (on systems supporting it), but it is close to impossible to have php do all the setup work for you (remounting a file system -o mand should be out of the scope of php, imho). George

« previous php.dev (#93806) next »