Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

What causes 'premature end of script headers'?

by markjugg (Curate)
on May 31, 2003 at 02:12 UTC ( #262011=categorized question: print w/replies, xml ) Need Help??
Contributed by markjugg on May 31, 2003 at 02:12 UTC
Q&A  > CGI programming


What are possible causes of the 'premature end of script headers' message in a web server's error log after the failed execution of a Perl CGI script?

Answer: What causes 'premature end of script headers'?
contributed by Aristotle

Not having output a header when you should have. Whether that is because the script didn't compile or was aborted before it reached the code to output the header, the result is the same. Consult your server's error log to find out the actual error message.

Answer: What causes 'premature end of script headers'?
contributed by markjugg

Here are some ideas:

  • Something printed to STDERR
  • The "Content-Type" header is invalid or missing.
  • You are using SuExec and it's causing problems.

For further ideas, you can:


Answer: What causes 'premature end of script headers'?
contributed by jhourcle

Something printing to STDOUT before the headers have been sent, and a blank line has also been sent to mark the end of the headers, or an incorrectly formatted header was sent. You can debug these issues by printing immediately print "Content-type: text/plain\n\n"; and looking at the output that is generated.

If you're using CGIwrap, you can use the debugging mode to see what content was generated, including the headers. suEXEC can also provide some debugging help.

Answer: What causes 'premature end of script headers'?
contributed by solegaonkar

I faced this problem because of DOS end of line characters in the file. Fixed with dos2unix

Answer: What causes 'premature end of script headers'?
contributed by LesleyB

You might have a bug in your code.

use CGI::Carp qw(fatalsToBrowser);

will throw errors up to the browser.

You can also run cgi scripts from the command line to check they actually run.

Answer: What causes 'premature end of script headers'?
contributed by gvs_jagan

You could encounter the 'premature end of script headers'

1) In case you were trying to accept values from a html page thru textfields

per se

print p("enter your name" , textfield("nam","");

missing out on one of the coats could cause it. For instance

print p("enter your name", textfield("nam , ""); #the end coat near nam is missing, this could cause

2) Also if you forget paranthesis near the html headers . In the below mentioned case missing out the paranthesis near the end_html could cause you the error

print header, start_html() ;
end_html();# leaving the paranthesis here

regards jagan

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2020-08-03 13:08 GMT
    Find Nodes?
      Voting Booth?
      Which rocket would you take to Mars?

      Results (27 votes). Check out past polls.