“Premature end of script headers” with baked views

Published on 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

    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

    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

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

  • petersendidit

    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

    @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

    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

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

  • bleevo

    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

    @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

    […] 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

    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

    @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

    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

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

  • Robin Upton

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

  • cakebaker

    @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

    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

    @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