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


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to