Bug #63709 [Ana]: flock() doesn't trigger mandatory locks on linux

From: Date: Fri, 07 Dec 2012 08:55:27 +0000
Subject: Bug #63709 [Ana]: flock() doesn't trigger mandatory locks on linux
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-175190@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63709&edit=1

 ID:                 63709
 User updated by:    eric dot saintetienne at gmail dot com
 Reported by:        eric dot saintetienne at gmail dot com
 Summary:            flock() doesn't trigger mandatory locks on linux
 Status:             Analyzed
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Linux
 PHP Version:        5.3.19
 Block user comment: N
 Private report:     N

 New Comment:

You're right, dio is a plain inteface to the underlying C function hence exposing 
real file descriptors (integers).

That's also what Python does: it exposes two different types of file objects: 
standard file objects via the builtin open() and file descriptors via os.open()

Is that is feasible with php?


Previous Comments:
------------------------------------------------------------------------
[2012-12-07 08:48:41] aharvey@php.net

My worry there is that dio resources are (as I recall, anyway) completely distinct from normal file
resources, so you couldn't fopen() a file and then dio_fcntl() it: it's all or nothing.

------------------------------------------------------------------------
[2012-12-07 08:42:12] eric dot saintetienne at gmail dot com

A fifth option is to pull the "Direct IO" extension into the mainline.
http://pecl.php.net/package/dio

This extension already expose fcntl() as well as a few other low-level
POSIX routines, and have some amount of testing as it's in its fourth
version already (though it's said to be in beta state)

------------------------------------------------------------------------
[2012-12-07 03:24:16] laruence@php.net

I like 3 :)

change the behavior of flock will intruduce a  visible bc break

------------------------------------------------------------------------
[2012-12-07 01:48:08] aharvey@php.net

The key difference between Python and PHP here is that Python always uses fcntl() internally,
whereas PHP will use flock() if it's available (which it obviously is on Linux) and will only
fall back to fcntl() if it's not. flock() will never create a mandatory lock, so the manual
page is wrong, which I'm pretty sure is my fault. Mea culpa.

We can probably fix this by switching to preferring fcntl() within our flock() function as Python
does, since that's actually the more useful behaviour, but that would be a (mild) BC break in
how flock() behaves in practice — although it would actually bring it into line with
what's documented.

The options I see are:

1. Change the behaviour of flock() as described above to prefer fcntl().
2. Add a new lockf() function, as suggested.
3. Just bite the bullet and expose fcntl() as a PHP function on POSIX platforms.
4. Do nothing and update the manual. :)

Does anyone have any thoughts? I'm happy to do the donkey work, but am not really sure on the
best way to proceed.

------------------------------------------------------------------------
[2012-12-06 14:19:38] eric dot saintetienne at gmail dot com

Note that dio_fcntl() of the "Direct IO" extension can successfully exclusively 
lock the file, but this shouldn't be considered as a workaround as it's not always 
possible to install extensions.

If flock() couldn't be modified for backward compatibility reasons, options could 
be added to alter its behaviour, or a new call lockf() would be welcome too.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=63709


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63709&edit=1


Thread (14 messages)

« previous php.bugs (#175190) next »