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:3
Avg. Score:3.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2019 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 04:01:26 2019 UTC