ZF-4134: Zend_Controller_Action_Helper_Json->sendJson() blocks front's dispatchLoopShutdown()

Issue Type: Bug Created: 2008-08-30T07:25:34.000+0000 Last Updated: 2011-08-14T14:08:44.000+0000 Status: Resolved Fix version(s): Reporter: Repeterr (peterr) Assignee: Pádraic Brady (padraic) Tags: - Zend_Controller

  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: - ZF-11444




<pre class="highlight">
 * Simplify AJAX context switching based on requested format
class Zend_Controller_Action_Helper_Json extends Zend_Controller_Action_Helper_Abstract
    // Suppress exit when sendJson() called
    public $suppressExit = false;

    // Encode JSON response and immediately send
    public function sendJson($data, $keepLayouts = false)
        $data = $this->encodeJson($data, $keepLayouts);
        $response = $this->getResponse();

        if (!$this->suppressExit) {

        return $data;

Everything's ok here only if we assume that no controller plugin adds http headers to Zend_Controller_Response. Otherwise, we get lack of expected headers inserted by FC's plugins.

For example, one of this affected plugin is Zend_Wildfire_Channel_HttpHeaders (extends Zend_Controller_Plugin_Abstract) which inserts firephp-related headers with its flush() method initially triggered by "_plugins->dispatchLoopShutdown()" in front controller.

h3.Test case Zend_Registry::get('log') returns Zend_Logger object with firebug writer.


<pre class="highlight">
Zend_Registry::get('log')->info('Test debug msg...'); // WILL send firebug headers

h4.Doesn't work

<pre class="highlight">
Zend_Registry::get('log')->info('Test debug msg...'); // Will NOT send firebug headers

h3. Temporary Workaround for Zend_Wildfire_Channel_HttpHeaders

<pre class="highlight">
$json = $this->getHelper('Json');
$json->suppressExit = true;


Posted by Christoph Dorn (cadorn) on 2008-09-01T09:21:57.000+0000

For Zend_Wildfire_Channel_HttpHeaders, the problem could be solved by registering a listener/plugin on Zend_Controller_Response that gets notified when sendResponse() or more specifically sendHeaders() is called. This would work for any other plugins that need to send headers as well.

Posted by Christoph Dorn (cadorn) on 2008-09-04T08:37:34.000+0000

See ZF-4181 for another reason for needing a listener for sendHeaders() for the Response object.

Posted by Christoph Dorn (cadorn) on 2008-09-08T11:16:30.000+0000

Also reported here: ZF-4202

Posted by Pádraic Brady (padraic) on 2011-08-14T14:08:43.000+0000

Marked as won't fix for the following reasons:

  1. The helper explicitly notes that it's purpose it to immediately send the response when called sendJson().
  2. I can see two possible solutions for deferring the immediate sending using the sendJson() and direct() methods to return the JSON without calling sendResponse().

It appears that the issue is not a bug but a disagreement over the nature/API of the helper. Such disagreements do not constitute a valid issue.

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.