|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42468 Write lock on file_get_contents fails when using a compression stream
Submitted: 2007-08-29 11:03 UTC Modified: 2007-09-03 02:54 UTC
From: daan at react dot nl Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.2CVS-2007-08-29 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: daan at react dot nl
New email:
PHP Version: OS:


 [2007-08-29 11:03 UTC] daan at react dot nl
When using the LOCK_EX flag for the file_put_contents function, and the filename is a compression stream, no data is written.

Conversely, it does work when the flag is not added, or when no compression is used.

Reproduce code:
	file_put_contents('compress.zlib://test.txt', 'blabla', LOCK_EX);


Expected result:
The string 'blabla'

Actual result:
An empty string


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-29 11:46 UTC]
Ilia, this should output an error when a wrapper does not support setting options. You shouldn't try locking if a wrapper doesn't support it.
 [2007-08-29 12:05 UTC] daan at react dot nl
Ah it does not say so anywhere in the streams documentation that locking is (or is not) supported - or is this tied in with one of the stream attributes as listed on ?
 [2007-08-30 03:19 UTC] crrodriguez at suse dot de
Index: ext/standard/file.c
RCS file: /repository/php-src/ext/standard/file.c,v
retrieving revision 1.409.
diff -u -p -r1.409. file.c
--- ext/standard/file.c 12 Aug 2007 17:09:59 -0000      1.409.
+++ ext/standard/file.c 30 Aug 2007 03:16:42 -0000
@@ -610,6 +610,14 @@ PHP_FUNCTION(file_put_contents)

+       if(flags & LOCK_EX && !php_stream_supports_lock(stream)) {
+               php_stream_wrapper *wrapper;
+               wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC);
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s does not support locking", ((wrapper && wrapper->wops->label) ? wrapper->wops->label : "Wrapper"));
+               php_stream_close(stream);
+               RETURN_FALSE;
+       }
        if (flags & LOCK_EX && php_stream_lock(stream, LOCK_EX)) {
 [2007-09-03 02:54 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 12:01:29 2024 UTC