Re: Premature end of script
by arturo (Vicar) on Aug 12, 2002 at 18:29 UTC
|
When you say "works fine when I run it on the command line", does it output a proper header? Do you have
print CGI::header(); or print "Content-type:text/html\n\n";, or some variant thereof in your script?
Other possibilities are that the webserver does not have both read and execute permissions on the file, or that your script depends crucially on some environment variable's being set a certain way in order to run.
Post your code, so we can get a better handle on your situation.
I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche
| [reply] [d/l] [select] |
Re: Premature end of script
by sauoq (Abbot) on Aug 12, 2002 at 18:34 UTC
|
It's kind of difficult to answer this without seeing the code or, at least, some output. You say it "works fine" from the command line but what does that mean exactly?
The errors indicate that the headers aren't correct. Are you remembering to print a Content-type header? Are you properly ending your headers with a blank line?
Your output should probably look something like:
Content-type: text/html
<html>
.
.
.
</html>
Of course, that's just a guess.
-sauoq
"My two cents aren't worth a dime.";
| [reply] [d/l] |
|
I was creating a GD(.pm) object before my header() call. This never gave an error before, so perhaps a newer version of GD.pm was installed on the machine - a vesion which perhaps outputs an image header when creating the object..
| [reply] |
Re: Premature end of script
by neilwatson (Priest) on Aug 12, 2002 at 18:32 UTC
|
| [reply] |
Re: Premature end of script
by fglock (Vicar) on Aug 12, 2002 at 19:38 UTC
|
This is a helpful checklist by Tom Christiansen.
It might give you some hints:
http://www.perl.com/doc/FAQs/cgi/idiots-guide.html
a version which perhaps outputs an image header when creating the object..
Try putting your header in the very beginning of the
script, and use $| = 1
| [reply] [d/l] |
Re: Premature end of script
by mikeirw (Pilgrim) on Aug 13, 2002 at 03:12 UTC
|
| [reply] |
Re: Premature end of script
by BorgCopyeditor (Friar) on Aug 13, 2002 at 01:37 UTC
|
I don't know whether this matters, but http defines the header as "Content-Type:"
BCE --Your punctuation skills are insufficient!
| [reply] |
|
I don't know whether this matters, but http defines the header as "Content-Type:"
It doesn't. Section 4.2, "Message Headers" of rfc2616 states:
Field names are case-insensitive.
Although the RFC is mostly consistent in its use of "Content-Type", there is an example under Section 19.2, "Internet Media Type multipart/byteranges" where the capitalization "Content-type" is used three times.
My own use of that capitalization is a habit. I can trace it back to the examples in the first printing of "the mouse" which was my primary reference when I started writing CGI scripts. That was Way Back When[tm] it was still CGI Programming on the World Wide Web rather than CGI Programming with Perl, authorship wasn't shared, and cgi-lib.pl was still preferred for two reasons: Lincoln hadn't turned his buggy CGI::* modules into a coherent and stable CGI.pm yet and a lot of us were still using perl4.
As if this answer wasn't long enough, I had a look at the CGI 1.1 Specification draft Revision 03 (expired) too. It uses both capitalizations as well. The BNF seems to indicate that the script is to return a "Content-type" field.
This answer is long enough now that I might as well turn it into a soap box (for completeness if nothing else.) So, if you think an RFC specifying CGI makes sense, ping Ken Coar about it. The effort pretty much came to a halt after revision 3 of the draft. I did get a response from Ken on the CGI-WG list in early June though, so there might still be hope.
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
|
Thanks for the correction, sauoq. I thought it might be case-insensitive, but couldn't find (in my all-too-brief search) the relevant RFC(s). Proof that unofficial sources are not to be trusted. :-/
BCE --You'reYour punctuation skills are insufficient!
| [reply] |
Re: Premature end of script
by Phaysis (Pilgrim) on Aug 13, 2002 at 07:25 UTC
|
Baz-
Several things could happen when you get this error in your
server log. Most times, the answer is transparently under
your nose. Assuming you are running Perl under Apache on
Linux, here is a quick checklist:
First - source code: make sure each line of code in your script is
terminated by the proper newline
for the platform you're on; if you're on *Nix, use only
linefeeds "<LF>", not "<CR><LF>" as you
would use on Win32 or "<CR>" as you would use on Mac.
Transferring your script via FTP in ASCII mode would solve
this.
Second - permissions: make sure your webserver has world-read and
world-execute permission to run this script. Try
chmod +755.
Third - headers: make sure your script first outputs the proper HTTP
headers before any document data is output. One of those
headers must be the Content-Type: header,
whose value is the mime-type of the document your script
outputs (usually "text/html"). The HTTP headers
must be seperated from the document
body by two linefeeds to tell the server that you are finished
outputting the headers. The web server will cough if it cannot determine
the mime type; it needs to communicate this to the user agent.
Premature end of script headers is a very vague
and confusing term, yes. Bitten me several times. These
considerations have always helped me recover.
-Shawn
(Ph) Phaysis
If idle hands are the tools of the devil, are idol tools the hands of god? | [reply] [d/l] [select] |