Zend - header already sent

Topics: Developer Forum, User Forum
Feb 11, 2010 at 10:12 PM

on a Apache/2.2.3 (Debian) mod_jk/1.2.18 mod_python/3.2.10 Python/2.4.4 PHP/5.2.0-8+etch16 mod_ssl/2.2.3 OpenSSL/0.9.8c mod_perl/2.0.2 Perl/v5.8.8

I receive this error

Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in , line 0'

I have investigated and it is caused from ->save("php://output"), headers_sent() function in zend response object return true!!! after this call

I substituted ->save("php://output") with ->save("-") and now all performs good

Coordinator
Feb 12, 2010 at 12:10 PM

->save("php://output") writes the Excel workbook directly to the browser. Because this is output to the browser, PHP also sends its standard headers to the browser immediately before the workbook.

->save("-") writes the Excel workbook to a file called '-' in the current working directory

 

I've not used PHPExcel with ZF, but if you're sending PHPExcel output to the browser before ZF sends its own headers to the browser, you will get this error

Feb 12, 2010 at 12:28 PM

I look in the source of PHPExcel_Writer_Excel5 (@version    1.7.2, 2010-01-11) but "-" create a temp file and it uses fpassthru($this->_FILEH_); to send output, I though  sending to php://stdout with ob_start() and output_buffering = true (enabled in every request of Zend_Framework) the headers would remain in the PHP output buffer ... is it wrong ? writing directly to the handle seems to flush ob_buffer maybe ? thanks I have not a deep knowledge of php's internals, but I would think php://output was governed by output_buffering settings

Coordinator
Feb 12, 2010 at 5:10 PM
oreficematteo wrote:

I have not a deep knowledge of php's internals, but I would think php://output was governed by output_buffering settings

 http://bugs.php.net/bug.php?id=42473