Bug #61201 [Opn]: LOCK_EX in file_put_contents with custom streamwrapper fails
| From: | cataphract@php.net | Date: | Sat, 03 Mar 2012 20:37:43 +0000 |
| Subject: | Bug #61201 [Opn]: LOCK_EX in file_put_contents with custom streamwrapper fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168081@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61201&edit=1
ID: 61201
Updated by: cataphract@php.net
Reported by: s dot kleff at goalio dot de
Summary: LOCK_EX in file_put_contents with custom
streamwrapper fails
Status: Open
Type: Bug
Package: Filesystem function related
Operating System: Win7/64
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
LOCK_EX is currently only supported for regular files (except if FILE_APPEND is used). This is due
to the new opening mode 'c' added after bug #43182 that presumably the stream wrappers
written at that time wouldn't support. Your script generates the following warning:
Warning: file_put_contents(): Exclusive locks may only be set for regular files
Although this works as designed, I think this should be revisited. I'll reclassify this as
request.
Previous Comments:
------------------------------------------------------------------------
[2012-02-28 13:51:17] s dot kleff at goalio dot de
Description:
------------
Currently I'm using a custom Streamwrapper for memcached access. The wrapper works
fine unless I'm using the LOCK_EX parameter for file_put_contents.
If the parameter is given the function does neither write the file nor calls a
method of the streamwrapper. I included simple echo statements in all methods of
the streamwapper but no output is shown.
I have done this because there is no documentation about which streamwrapper
methods are called during file_put_contents. I ASSUME that it should call
stream_lock like flock() does - but as mentioned before there is no output at all.
Test script:
---------------
class MyWrapper {
// Assume other methods are implemented
// Just for demonstration
public function stream_lock($operation) {
echo "I've been called";
}
}
stream_register_wrapper('myWrapper, 'MyWrapper');
$result = file_put_contents('myWrapper://myFile','content',LOCK_EX);
echo $result;
Expected result:
----------------
true
(file is written)
Actual result:
--------------
false
(file is not written)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61201&edit=1