ZF-3396: Zend_Cache - Zend_Log - When using the php://output stream

Issue Type: Bug Created: 2008-06-05T10:03:31.000+0000 Last Updated: 2009-01-09T09:53:14.000+0000 Status: Resolved Fix version(s): Reporter: Helgi Hrafn Halldórsson (harabanar) Assignee: None Tags: - Zend_Log

Related issues: Attachments: - zend_log_writer_stream_testcase.php


My coworkers and I found this out the VERY hard way .. but here it comes.

When using logging with Zend_Cache but not setting the logger option. Zend_Cache uses Zend_Log_Writer_Stream('php://output') as default logger. This can cause some trouble. Because on destruction the Zend_Log_Writer_Stream does a fclose on its stream. So if the Zend_Cache is destroyed, no more output can be sent. In our opinion the _php://output_ should never be closed. This can therefor be thought of as a bug in PHP (hmm :D). But as a fix for the ZendFramework we suggest this patch ..

<pre class="highlight">
Index: Log/Writer/Stream.php
--- Log/Writer/Stream.php   (revision 9612)
+++ Log/Writer/Stream.php   (working copy)
@@ -43,6 +43,13 @@
     protected $_stream = null;
+     * Is the stream the <a>php://output</a> or not
+     *
+     * @var bool
+     */
+    protected $_isPhpOutput = false;
+    /**
      * Class Constructor
      * @param  streamOrUrl     Stream or URL to open as a stream
@@ -61,6 +68,7 @@
             $this->_stream = $streamOrUrl;
         } else {
+            if($streamOrUrl == "php://output") $this->_isPhpOutput = true;
             if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
                 $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
                 throw new Zend_Log_Exception($msg);
@@ -77,7 +85,7 @@
     public function shutdown()
-        if (is_resource($this->_stream)) {
+        if (is_resource($this->_stream) && !$this->_isPhpOutput) {


Posted by Fabien MARTY (fab) on 2008-06-06T12:17:36.000+0000

doesn't seem to be a Zend_Cache problem, so I remove the "Zend_Cache component" tag

please, correct if I didn't understand

Posted by Benjamin Eberlei (beberlei) on 2008-11-07T05:16:02.000+0000

{quote} /** * @group ZF-3396 */ public function testShutdownDoesNotClosePhpOutputStreamResource() { $writer = new Zend_Log_Writer_Stream('php://output', 'w+');

    $writer->write(array('message' => 'this write should succeed'));


    echo "TEST";
    $output = ob_get_contents();
    $this->assertEquals("TEST", $output);

    $fp = fopen('<a rel="nofollow" href="php://output">php://output</a>', 'w+');
    fwrite($fp, "TEST");
    $output = ob_get_contents();

    $this->assertEquals("TEST", $output);

This works for me even WITHOUT your patch. Can you give a test-case were your bug applies and it fails?

Posted by Benjamin Eberlei (beberlei) on 2008-11-07T05:17:53.000+0000

Hm wiki markup sucks. I have attached a file with the testcase. Please Review and give a better failure case.

Posted by Helgi Hrafn Halldórsson (harabanar) on 2008-11-07T05:55:06.000+0000

Hi again ..

We will come with a better description on how we got this error.

Thank you for your time, so far :D

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.