|  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
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
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
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:
(file is written)

Actual result:
(file is not written)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-03 20:37 UTC]
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]
-Type: Bug +Type: Feature/Change Request
 [2018-03-11 13:03 UTC]
-Package: Filesystem function related +Package: Streams related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 18:01:30 2024 UTC