"Premature end of script headers at header.cgi"
Main Topics
Browse All TopicsI have Apache 2.x, PHP 5.x installed in Linux server. The application has PHP files in the document root and 2 .cgi files (upload.cgi and progress.cgi) in the apache's cgi-bin directory. The upload.cgi takes care of uploading the file from the client to the server and the progress.cgi displays the progress bar of how much % of data is being transferred. So, basically the application is a mixture of PHP and Perl (since PHP doesn't handle the raw POST data)! Now, everything works fine and great!!
Problem is in the production environment. They have Apache 1.3 and PHP 5.x installed in Linux server. Small images less than say 500 KBytes works just fine. If the image is > 500 KByte, the progress bar works till 99% and upload.cgi reports "An internal server occurred". The apache error log says: "Premature end of scripts at header.cgi". This happens for 1MB image as well as 4.5MB image file but not for the < 500 KB image files!
I checked the max_upload_time, upload limit, etc., everything is okay. I wonder why this problem occurs only if the file size is bigger!
Please advise.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi ldbkutty,
the problem appears when the file size exceed 500kb. I had the impression that this is something to do with the PHP configuration, or the script setting, or maybe the server configuration -- check for how the data is transferred to the server -- either via POST of GET method.
you may also want to look at the server error_log file for some indication of the error. if this is something to do with size limit, then obviously the error would register there.
Some other discussion that may be useful to get some hint -- there was just too much information posted that I could not paraphrase -- http://gallery.menalto.com
cheers.
aha.... that must be something to do with how dos/windows and unix did to the EOL (end of line) marker. Somehow, transferring file between these two systems may give (myself) nightmare sometime.
I think there is a command called dos2unix and unix2dos that you could use to convert the file --- ie, if you edit the file in windows, and ftp that to unix, try running "dos2unix file.cgi", vice-versa.
cheers
Yes, the problem was caused by line endings. Windows will use CR-LF as line ending, while unix uses only LF.
So your first line:
#!/usr/bin/perl<CR><LF>
Since unix considered LF to be the end of line, it was looking for /usr/bin/perl<CR> to execute your script, which doesn't exist.
If you upload the files using FTP in ASCII mode, that will solve the problem. Or if you can't do that, if you put a space at the end of the line, that will solve the problem also (well, it won't get rid of the windows line endings, but unix will at least use the right program), like so:
#!/usr/bin/perl <space>
Business Accounts
Answer for Membership
by: Adam314Posted on 2007-03-28 at 08:06:40ID: 18808682
Have you looked at the error log? What is the error reported?