• On a live site I am working on they have been getting these errors when using the Dashboard:

    [Mon Mar 14 17:08:38 2011] [error] [client xx.xxx.xxx.xxx] Premature end of script headers: index.php
    [Mon Mar 14 17:21:15 2011] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: index.php
    [Mon Mar 14 17:21:35 2011] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: index.php
    [Mon Mar 14 17:33:11 2011] [error] [client xx.xx.xx.xx] Premature end of script headers: index.php
    [Mon Mar 14 18:01:44 2011] [error] [client xx.xx.xx.x] Premature end of script headers: edit-comments.php, referer: https://www.domain.com/wp-admin/edit-comments.php?comment_status=all
    [Mon Mar 14 18:09:27 2011] [error] [client xx.xx.xx.x] Premature end of script headers: edit-comments.php, referer: https://www.domain.com/wp-admin/edit-comments.php?comment_status=trash&deleted=20
    [Mon Mar 14 18:09:57 2011] [error] [client xx.xx.xx.x] Premature end of script headers: index-extra.php, referer: https://www.domain.com/wp-admin/index.php

    SOmetimes certain pages lead to 404s until I reload. Never had this before. Any ideas?

Viewing 12 replies - 16 through 27 (of 27 total)
  • I just learned that if any content (even whitespace) accidentally appears after a php file’s closing tag (the final ?>), it can be sent to the browser (which actually makes perfect sense).

    This can cause the ‘premature end of script header’ error if such output ends up in the wrong place in the generated HTML.

    It is now considered best practice (by some, such as the Zend framework) to always leave out the final php closing tag (no ?> at the end of any php file). PHP interprets the end-of-file as the implicit close. This prevents extra text output after the closing tag.

    Notice that a new install of WordPress will have no closing tag at the end of wp-config.php, for example.

    It seems that any number of plugins/themes could have bogus output after the close tag, causing this exception when pages are loaded in specific cases.

    Can anyone with more PHP expertise recommend a way to diagnose/verify/address this failure?

    @nyhm (love the DW icon BTW – was that a Warlock?) I think you might be confusing 2 different types of errors. I DO support leaving the closing ?> off of the end of any pure PHP file, but the thing that I think it mostly affects is when you want to modify headers using the PHP header() function. If you have

    <?php
    
    // do nothing
    
    ?> <?php 
    
    header('Location:https://google.com'); 
    
    ?>

    It will throw an error that ‘headers cannot be modified’ because of ‘script output at line xxx’, which is caused by the space between the two script blocks. If the first script block was in an include file and it had whitespace at the end, it would still be a problem to include before the call to header().

    Could it be you mixed up the two, or are you saying that this condition can cause both types of errors? You may know something I don’t.

    @jrevillini Wizard (Warlock was the tougher variant).

    I see what you are saying about the gap in the php tags.

    Honestly, I’m just casting spells in the dark here, trying to get an excellent move…

    OK, sorry. I’m trying to figure out why I get Premature end of header errors all the time. I’m only Magician-level when it comes to PHP/Web development. I need some more experience to level up…

    Sorry again. In all seriouslessness, I’d appreciate any advice you/anyone can give regarding slaying this evil dragon lord of a bug (yeah, that was pretty bad).

    I’m having the same problem on several of my WP sites. Seems like it happens more with some than others. My educated guess is that it’s related to the load since it seems to happen more often with my higher traffic sites. All are hosted on DreamHost with a single account.

    @rhand – if you’re still paying attention… How do I turn on debugging? Looks like it might be a good way to identify plugins that could cause the issue.

    @nelswadycki – same here … bunch of sites on one Dreamhost account. a lot of people who have this problem are on DH so we may want to take it to them. They have the throttle controls, so I would imagine they have the logs which might indicate where things are spiking and/or dying.

    Thread Starter Rhand

    (@rhand)

    @ nelswadycki Yeah still following this thread. Less issues now without the use of Shopp though. Add

    define('WP_DEBUG',true);  // Turn debugging ON

    to your wp-config.php to print errors in front end.

    Thanks for the debug tip. I’m still seeing the premature end of script errors, too, but less often. I’m not sure what has changed, though.

    Is there a way to direct the WP debug to a log file?

    Thread Starter Rhand

    (@rhand)

    @ https://fuelyourcoding.com/simple-debugging-with-wordpress/ I found this cool snippet:

    define('WP_DEBUG_DISPLAY', false); // Turn forced display OFF
      define('WP_DEBUG_LOG',     true);  // Turn logging to wp-content/debug.log ON

    to store logs and hide the display. Did not know about these WP definitions. Very useful.

    @rhand, Thanks for the tip. I tried it, and it dumps so many PHP notices that I’d be lucky to stumble upon the culprit. Is that normal for WordPress?

    Thread Starter Rhand

    (@rhand)

    Normally a regular homepage should only show a few errors. Unless you have plugins that cause more that is.. Perhaps you can put the errors at a pastebin an add a link here so people can have a look.

    change .htaccess file to htaccess and refresh

    anyone ever find out what was wrong with your errors? I seem to be having this same issue.

    I’ve tried just about everything: plugins deactivated, removed, theme change, lowering memory usage, switching from FastCGI, pinging, tracert.

    I use GoDaddy and am pretty good with code, especially PHP. I receive the Premature end of script headers which either leads to the page displaying 500 internal server error, a page saying I don’t have permissions, logging me out or a simple cannot load page.

    Mostly the 500 internal server error though and always a premature end of script headers index.php in my error log along with a timeout 120 seconds log.

Viewing 12 replies - 16 through 27 (of 27 total)
  • The topic ‘Backend Errors:: Premature end of script headers’ is closed to new replies.