“Premature end of script headers” with baked views

Published on July 18, 2007 and tagged with cakephp  problem

After deploying a simple application baked with the bake script I noticed a strange effect: requesting the index or edit action caused the following error: “Not found – The requested address internalerror.html was not found on this server.”. And the error log of Apache contained this error: “Premature end of script headers: php5.cgi”. Strange, it worked fine on my local server…

After some debugging I could locate the line which caused the problem:

<?php echo $html->link(__('Delete', true), array('action'=>'delete', $entry['Entry']['id']), null, __('Are you sure you want to delete', true).' #' . $entry['Entry']['id']); ?>

Or more precisely:

__('Are you sure you want to delete', true)

Don’t ask me why that doesn’t work on Dreamhost ;-)

As I don’t need multi-language support, the workaround is simple:

<?php echo $html->link(__('Delete', true), array('action'=>'delete', $entry['Entry']['id']), null, 'Are you sure you want to delete #' . $entry['Entry']['id']); ?>

Maybe this will help someone…

18 comments baked

  • theman July 18, 2007 at 18:39

    I noticed this in one of the google group posts as well. http://groups.google.ca/group/cake-php/browse_frm/thread/cf9a793ddfad1e6a/8c0cf50150895283
    The guy there thought it had to do with the Zend Optimizer? Seems kind of weird though.

  • carsten July 19, 2007 at 13:05

    I can confirm that:
    had that very same issue at the German hosting provider HostEurope and there it was the ZendOptimizer causing the problems, as well.

  • cakebaker July 19, 2007 at 17:49

    @theman, carsten: Thanks for the hint that ZendOptimizer could be the problem.

  • petersendidit July 19, 2007 at 20:28

    I am on dreamhost and had the same problem. It is Zend Optimizer v3.2.2. I found a post the said that Zend Optimizer 3.2.6 no-longer has that problem.

    http://www.zend.com/forums/index.php?t=msg&goto=7323&S=f987dc025b5261de2b20e8

    I have made dreamhost aware of this. They said they will be upgrading Zend Optimizer “in due time”

    The other option to get around it is to compile your own copy of PHP with the newest version of Zend Optimizer.

  • cakebaker July 21, 2007 at 10:27

    @petersendidit: Thanks for the link.

    Yeah, I got the same answer from Dreamhost. At the moment I will work with the workaround I described, as I am too lazy to compile my own version of PHP ;-)

  • farmer August 30, 2007 at 00:09

    Thanks, I’m also on dreamhost and was pulling my hair out. Didn’t realize dreamhost would allow you to compile your own php.

  • cakebaker August 30, 2007 at 09:23

    @farmer: Yes, they describe it somewhere in the wiki (http://wiki.dreamhost.com) how to compile your own PHP. Good luck with it :)

  • bleevo September 23, 2007 at 02:11

    Hey cakebaker,

    I deleted all the code out of my view and it is still throwing this error what would you suggest i do to fix it.

  • cakebaker September 25, 2007 at 19:08

    @bleevo: Hm, maybe you are using a helper which uses this function? Difficult to say what causes this problem in your case…

  • Jon Sykes » Blog Archive » Premature end of script headers: php5.cgi September 24, 2008 at 23:14

    [...] googled, tried advice on cakebaker, and other locations. I would really rather not try to recompile php down to php4 or with php and [...]

  • Jon Sykes September 24, 2008 at 23:50

    Cakebaker, any other suggestions, I went in an renamed __ then I made it so it just output $msg and did nothing else.

    I only get the error if my dynamic page is in the root router position, as soon as I make sites controller index be fired from something other than just blah.com/ it works. Totally head scratching.

  • cakebaker September 25, 2008 at 16:57

    @Jon: Hm, did you check the version of the zend optimizer? But it’s difficult to say what could be the problem, personally I use the “/” route without any problems on dreamhost. Maybe someone in the IRC channel or google group has an idea what could be the cause of the problem?

  • dave rupert October 16, 2008 at 18:26

    thanks cakebaker, i had this problem last night on a MediaTemple Grid Server. new site launch and suddenly the site started throwing this error. i think i owe you a $1000 for the tip off. once i’m a googillionaire, the check is in the mail.

  • cakebaker October 16, 2008 at 19:27

    @dave: Cool, I’m looking forward to it ;-)

  • Robin Upton August 02, 2009 at 06:15

    I just got this from my dreamhost account, so it seems they still didn’t fix it :-(

  • cakebaker August 02, 2009 at 17:20

    @Robin: Hm, I just tested the statement from the article on my dreamhost account and it works. Did you check the version of Zend Optimizer with phpinfo()? (back when I wrote this article it was an issue with Zend Optimizer)

  • Robin Upton August 06, 2009 at 10:12

    They’re running v3.3.3. I won’t be surprised it it’s not this error. Maybe connected to output buffering, since on localhost, it outputs to the screen, but on Dreamhost it shows nothing, just the “Premature end of script headers” in the output log.

  • cakebaker August 06, 2009 at 16:43

    @Robin: Strange. Maybe it helps to contact their support? (sorry for no other idea…)

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License