php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daan at react dot nl
New email:
PHP Version: OS:

 

 [2007-08-29 11:03 UTC] daan at react dot nl
Description:
------------
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:
---------------
<?php
	file_put_contents('compress.zlib://test.txt', 'blabla', LOCK_EX);

	var_dump(file_get_contents('compress.zlib://test.txt'));


Expected result:
----------------
The string 'blabla'

Actual result:
--------------
An empty string

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-29 11:46 UTC] jani@php.net
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 http://php.net/manual/en/wrappers.compression.php ?
 [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.2.6.2.26
diff -u -p -r1.409.2.6.2.26 file.c
--- ext/standard/file.c 12 Aug 2007 17:09:59 -0000      1.409.2.6.2.26
+++ ext/standard/file.c 30 Aug 2007 03:16:42 -0000
@@ -610,6 +610,14 @@ PHP_FUNCTION(file_put_contents)
                RETURN_FALSE;
        }

+       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)) {
                php_stream_close(stream);
                RETURN_FALSE;
 [2007-09-03 02:54 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC