|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44501 file_put_contents writes empty file with zlib and LOCK_EX
Submitted: 2008-03-22 03:06 UTC Modified: 2011-11-16 12:33 UTC
Avg. Score:3.7 ± 1.2
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: david at acz dot org Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.2.5 OS: SLES 10 x86_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.
Bug Type:
From: david at acz dot org
New email:
PHP Version: OS:


 [2008-03-22 03:06 UTC] david at acz dot org
When passing LOCK_EX to file_put_contents() using a "compress.zlib" stream, the function creates a valid gzip file (non-empty) containing zero un-compressed bytes (gunzip outputs nothing) and returns false.

This was reported in #42468, but wasn't actually fixed.  The function needs to fail BEFORE it opens (and destroys) the output file.

Reproduce code:
    $name = "/tmp/hello.txt.gz";
    $file = "compress.zlib://" . $name;

    var_dump(file_put_contents($file, "hello", LOCK_EX));

Expected result:
string(5) "hello"

Actual result:
string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-25 13:33 UTC]
Ilia, the fix propably wasn't quite right, and I get this with the example script:

[jani@localhost ~]$ /home/jani/src/build/php_5_2/sapi/cli/php  t.php

Warning: file_put_contents(compress.zlib:///tmp/hello.txt.gz): failed to open stream: Inappropriate ioctl for device in /home/jani/t.php on line 5
string(0) ""
/home/jani/src/php-5.2/main/streams/streams.c(390) : Stream of type 'STDIO' 0x9504c4c (path:/tmp/hello.txt.gz) was not closed
[Tue Mar 25 15:30:11 2008]  Script:  't.php'
/home/jani/src/php-5.2/main/streams/streams.c(227) :  Freeing 0x09504C4C (128 bytes), script=t.php
/home/jani/src/php-5.2/ext/zlib/zlib_fopen_wrapper.c(127) : Actual location (location was relayed)
=== Total 1 memory leaks detected ===

 [2008-05-06 14:04 UTC] andron at kpi dot ua
I have the same problem
/var/tmp/portage/dev-lang/php-5.2.6/work/php-5.2.6/main/streams/streams.c(390) : Stream of type 'STDIO' 0x8386378 (path:./storage/706e362fa415aa530247b0c4a372b249) was not closed

What infomation you need too?
 [2008-09-16 00:27 UTC]
Please try using this CVS snapshot:
For Windows (zip):

For Windows (installer):

Seems to work fine in 5.3 CVS
 [2008-09-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2011-11-16 12:33 UTC]
-Status: No Feedback +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 03:01:28 2024 UTC