#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Modesto, CA
    Posts
    4
    Rep Power
    0

    "Content-type:text/html\n\n" repeating over and over... hanging server


    I see this occasionally... the string "Content-type:text/html\n\n" will repeat endlessly when executing a script... except that I have *NO* loops in my code that would cause this to happen...

    Any ideas?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Another pair of eyes on your code might see the problem.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Modesto, CA
    Posts
    4
    Rep Power
    0

    Hmmmmmmm...


    Originally Posted by FishMonger
    Another pair of eyes on your code might see the problem.
    That might be difficult. There are over a million lines spread over 667 scripts.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Sorry, my crystal ball stopped working.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Modesto, CA
    Posts
    4
    Rep Power
    0

    Quick Sample


    OK, here is a very abbreviated code sample that's producing this error...

    Code:
    #!/usr/bin/perl
    
    require "Backup.pl";
    
    use CGI qw(param);
    use CGI::Carp qw(fatalsToBrowser);
    use DBI;
    
    if (param()) {
    	if (param('a')) {
    		$Action = param('a');
    	}
    	if (param('File1')) {
    		$file1 = param('File1');
    	}
    	if (param('File2')) {
    		$file2 = param('File2');
    	}
    	if (param('File3')) {
    		$file3 = param('File3');
    	}
    	if (param('File4')) {
    		$file4 = param('File4');
    	}
    	if (param('File5')) {
    		$file5 = param('File5');
    	}
    	if (param('File6')) {
    		$file6 = param('File6');
    	}
    	if (param('File7')) {
    		$file7 = param('File7');
    	}
    	if (param('File8')) {
    		$file8 = param('File8');
    	}
    	if (param('File9')) {
    		$file9 = param('File9');
    	}
    	if (param('File10')) {
    		$file10 = param('File10');
    	}
    }
    
    if ($Action eq "main") {
    #	print "<p><h3>Got here.</h3></p>";
    	&TracyUploadAdmin();
    } elsif ($Action eq "b") {
    	&ProcessTracyUploads($file1,$file2,$file3,$file4,$file5,$file6,$file7,$file8,$file9,$file10);
    	print "Content-type:text/html\n\n";
    	print "<p><h3>All files uploaded successfully.</h3></p>";
    } else {
    	print "Content-type:text/html\n\n";
    	print "<p><h3>I don't know what you want me to do.</h3></p>";
    }
    exit;
    The file being included is shown below:

    Code:
    sub TracyUploadAdmin { 
    
    print "Content-type:text/html\n\n";
    print << "END";
    	<html>
    	<body>
        <form method="post" action="./upload_central.cgi" enctype="multipart/form-data">
        <INPUT TYPE="hidden" NAME="a" VALUE="b">
        <table width="1200" border="0" cellpadding="0" cellspacing="0" align='center'>
        <tr>
        <td colspan='3'><div align='center'><img src='../images/vaultbanner.jpg' width='1200' height='200'></div></td>
        </tr>
        <tr>
        <td colspan="3"><div align="right"><font face="Arial, Helvetica, sans-serif" size="5"><b>Upload Backup Transcripts</b></font></div></td></tr>
        <tr><td colspan="3">&nbsp;</td></tr>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #1: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File1" size='75'></font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #2: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File2" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #3: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File3" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #4: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File4" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #5: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File5" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #6: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File6" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #7: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File7" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #8: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File8" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #9: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File9" size='75'></font></td>
        </font></td>
        </tr>
        <tr>
        <td width="15%" height="29" bgcolor="$GBL_Line_Accent">
        <div align="right"><b><font face="Arial, Helvetica, sans-serif" size="2">Upload #10: </font></b></div>
        </td><td width="3%" bgcolor="$GBL_Line_Accent">&nbsp;</td>
        <td width="82%" height="29"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;&nbsp;
        <input type="file" name="File10" size='75'></font></td>
        </font></td>
        </tr>
        <tr><td colspan='3'><hr></td></tr>
        <tr><td colspan='3'><div align="center"><input type="submit" name="Submit" value="Backup Documents">&nbsp;&nbsp;<input type="reset" name="Submit2" value="Reset"></td></tr>
        </table>
        </form>
        </body>
        </html>
    END
    }
    
    sub ProcessTracyUploads {
    my ($file1,$file2,$file3,$file4,$file5,$file6,$file7,$file8,$file9,$file10) = @_;
    	
    	if ($file1) {
    		&DoTracyUpload($file1);
    	}
    	if ($file2) {
    		&DoTracyUpload($file2);
    	}
    	if ($file3) {
    		&DoTracyUpload($file3);
    	}
    	if ($file4) {
    		&DoTracyUpload($file4);
    	}
    	if ($file5) {
    		&DoTracyUpload($file5);
    	}
    	if ($file6) {
    		&DoTracyUpload($file6);
    	}
    	if ($file7) {
    		&DoTracyUpload($file7);
    	}
    	if ($file8) {
    		&DoTracyUpload($file8);
    	}
    	if ($file9) {
    		&DoTracyUpload($file9);
    	}
    	if ($file10) {
    		&DoTracyUpload($file10);
    	}
    	return;
    }
    
    sub DoTracyUpload {
    my $ufile = shift;
    
    my $uploadFile = $fileName = $ufile;
    $fileName =~ s!^.*(\\|\/)!!;
    $fileName = lc($fileName);
    my $exists = undef;
    my $uploadPath = "/home/edisroot/www/backup/1/$fileName";
    if (-e "/home/edisroot/www/backup") {				# See if the teacher directory exists.
    	$exists++;
    } else {									# If not, create it.
    	mkdir("/home/edisroot/www/backup",0777) || die print "Content-type:text/html\n\n<p><h3>Cannot mkdir to /home/edisroot/www/backup ($!)</h3></p>";
    }
    $exists = undef;
    if (-e "/home/edisroot/www/backup/1") {				# See if the teacher directory exists.
    	$exists++;
    } else {									# If not, create it.
    	mkdir("/home/edisroot/www/backup/1",0777) || die print "Content-type:text/html\n\n<p><h3>Cannot mkdir to /home/edisroot/www/backup/1 ($!)</h3></p>";
    }
    if ($ufile) {
    	open(OUTFILE, ">$uploadPath") or die print "<p><h3>ERROR: Could not open file [$fileName | $uploadPath]</h3></p>";
    	binmode(OUTFILE);
    	while (my $bytesread = read($ufile, my $buffer, 1024)) {
    		print OUTFILE $buffer;
    		}
    	close OUTFILE or die print "Content-type:text/html\n\n<p><h3>ERROR CLOSING FILE.</h3></p>";
    } 
    return;
    }
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    The code you posted doesn't provide a clear cut reason for the problem you're having, but that may just be because it's a condensed cherry picked portion of your script.

    However, I see a number of problems with that code.

    1) You're not using using the strict or warnings pragmas.

    2) You're not utilizing the methods in the CGI module, other than param().

    3) You have numerous print statements that output the content-type header. Now, I'm sure you believe that they don't overlap because you don't have a loop, but you don't necessarily need a loop to have that header statement printed from multiple points.

    Instead, you should be using the header() method from the CGI module and execute once near the top rather than all over place.

    4) If you use the upload() method in the CGI module in list context, you could get rid of those messy if (param(...)) blocks.

    5) A dispatch table would clean up the process of determining and executing the required "Action".

    6) The building of the table in the TracyUploadAdmin() sub is very messy and uses depreciated html code. It could be cleaned up and reduced to just a few lines by using a loop and the related methods in the CGI module and a little css.

    7) The error handling in the DoTracyUpload sub is weird. A die statement goes to stderr and a print statement goes to stdout. Combining them in a single statement doesn't make any sense and might even cause the problem you're experiencing.

    There are other issues I see, but that should be enough to get you thinking.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Modesto, CA
    Posts
    4
    Rep Power
    0
    Originally Posted by FishMonger
    There are other issues I see, but that should be enough to get you thinking.
    No, no cherry-picking. That was the whole thing. Thanks for the feedback. I'll look at the issues you brought up.

    incognitii

IMN logo majestic logo threadwatch logo seochat tools logo