php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61201 LOCK_EX in file_put_contents with custom streamwrapper fails
Submitted: 2012-02-28 13:51 UTC Modified: 2018-03-11 13:03 UTC
Votes:4
Avg. Score:3.2 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: s dot kleff at goalio dot de Assigned:
Status: Open Package: Streams related
PHP Version: 5.3.10 OS: Win7/64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: s dot kleff at goalio dot de
New email:
PHP Version: OS:

 

 [2012-02-28 13:51 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-03 20:37 UTC] cataphract@php.net
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.
 [2012-03-03 20:37 UTC] cataphract@php.net
-Type: Bug +Type: Feature/Change Request
 [2018-03-11 13:03 UTC] cmb@php.net
-Package: Filesystem function related +Package: Streams related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 04:01:38 2024 UTC