Edit report at https://bugs.php.net/bug.php?id=63709&edit=1
ID: 63709
Comment by: mi+php at aldan dot algebra 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:
I am puzzled, what can the current behavior be possibly used for?
If the lock is not really locking (and it does not -- neither on Linux nor on
FreeBSD), then why bother with it at all? And if nobody bothers, then why not
fix it properly?
BTW, at least, on BSD the different locking mechanisms create compatible locks:
The flock(), fcntl(2), and lockf(3) locks are compatible.
Processes using different locking interfaces can cooperate
over the same file safely. However, only one of such interfaces
should be used within the same process. If a file is locked by
a process through flock(), any record within the file will be
seen as locked from the viewpoint of another process using
fcntl(2) or lockf(3), and vice versa.
Previous Comments:
------------------------------------------------------------------------
[2012-12-07 09:43:12] eric dot saintetienne at gmail dot com
You're right, Python is smart and the trick is simple: fnctl module functions
are coded such that they detect the type of the object they're given as
argument. If it's an integer they assume it is a file descriptor otherwise they
call its fileno() method to retrieve the file descriptor integer.
So it's a matter of adding your own fileno() method to the PHP standard file
object and making the dio_* routines calling it, when not provided with an
integer.
Does that makes sense to you?
It's a suggestion, at the end of the day it's your decision of how to handle
this issue, even though it seems to, I'm actually not pushing to get direct io
integrated at any cost (I don't have any stake) but I just feel it's the way to
go.
------------------------------------------------------------------------
[2012-12-07 09:08:01] [email protected]
That's true, but they're still somewhat interchangeable in Python â higher
level file objects returned by open() work with fcntl methods. That wouldn't be
the case if we bundled dio without further work.
------------------------------------------------------------------------
[2012-12-07 08:55:27] eric dot saintetienne at gmail dot com
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?
------------------------------------------------------------------------
[2012-12-07 08:48:41] [email protected]
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)
------------------------------------------------------------------------
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