开发者

zend framework disable output for capture

开发者 https://www.devze.com 2023-04-13 05:42 出处:网络
I need to run post connection close processing (sending emails, refreshing caches etc) which take a long time. So in order to do this I have an action helper which will eventually down the line will c

I need to run post connection close processing (sending emails, refreshing caches etc) which take a long time. So in order to do this I have an action helper which will eventually down the line will check if anything needs to be done and process it.

Here's a simplified version of the output bit:

$this->getFrontController()->returnResponse(false);
$response = $this->getResponse();
$body = $response->getBody();
$response->setHeader('Connection', 'close');
ob_start();
echo $body;
$size = ob_get_length();
$response->setHeader('Content-length', $size);
ob_end_flush();
flush();
$this->run();

(Note, when live I intend on开发者_Python百科 using fastcgi_finish_request but this also needs to work locally. $this->run() runs the post processing functions, no output here).

I keep getting the ol' hated Headers Sent error with this, but the exception returns no file or line number where it happened (I am guessing this is because of the nature of action helpers in Zend).

Some digging has got the error down to the setHeader() call. But I thought with returnResponse(false) they wouldn't auto send?

Is my logic to output this correct?

Edit:

Another issue is that getReponse doesn't return anything because the layout render hasn't been called, but calling Zend_Layout::getMvcInstance()->render(); gives me the layout with no content rendered to $layout->content ?


I guess ob_end_flush() sends $body, etc. but $this->run() tries to send the headers afterwards. Try to use something like $content = ob_get_contents(); and ob_end_clean() to save the buffer content to a variable and to clear the buffer without sending. Then, you can echo $content after sending your headers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号