My upload script which uses upload hook works really nice. After the upload ends it writes some debug stuff to log file and sends some info to other host.

When client aborts the upload the reminder of the script after hook is not executed and i get an error in my apache log:

[Sat Mar 26 14:53:09 2011] [error] [client xxx.xxx.xxx.xxx] (70014)End + of file found: Error reading request entity data, referer: http://lo +calhost/upload
I'm thinking its the fault of apache, because without abort the script works just fine. Does anyone have any clue about it ? The script:
#!/usr/bin/perl -w use strict; use CGI; use warnings; use Digest::MD5 qw(md5_hex); use POSIX qw/ceil/; use POSIX 'setsid'; use LWP::Simple; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 1024 * 1024 * 2000000; our $php_exec = '/usr/bin/php'; our $www_root = 'www_root'; our $SERVER_NUMBER = '1'; our $pid = 666; our $data; our $first_hook = 1; our $sum_bytes = 0; our $approx_file_size = 0; our $original_filename = ""; our $storage_name = ""; our $db_path = "path where the file with number of stored files is"; our $upload_path = "path to storage folder"; our $debug_path = "path to log folder"; our $url = ''; our $content = ''; #zmienna identyfikuj&#261;ca urzytkownika wyci&#261;gni&#281;ta z +pola GET my $query_string = $ENV{QUERY_STRING}; my $sessid = $query_string; my $upload_session = $query_string; $sessid =~ m/userid=([0-9]+)/i; our $userid = $1; $upload_session =~ m/us=([a-zA-Z0-9]+)/i; our $upload_sess = $1; my $line = 0; #zmiana aktualnej ilo&#347;ci plików przechowywanych na serwerze open(UPLOAD_DB, "+<", $db_path."upload_db") or die "Cannot open : +$!"; flock(UPLOAD_DB, 2); $line = <UPLOAD_DB>; our $filenumber = $line + 1; seek(UPLOAD_DB, 0, 0); truncate(UPLOAD_DB, 0); print UPLOAD_DB $filenumber; close UPLOAD_DB; our $dir = ceil($filenumber/5); unless (-d $upload_path.$dir) { mkdir $upload_path.$dir, 0777; #print $!; } $upload_path = $upload_path.$dir."/"; our $logfile = $debug_path."hook_debug.txt"; our $q = CGI->new(\&hook, $logfile, 0); sub hook { our ($filename, $buffer, $bytes_read, $logfile) = @_; + $sum_bytes = $bytes_read; if($first_hook) { $approx_file_size = $ENV{CONTENT_LENGTH}; #print $approx_file_size.'\n<br />'; $approx_file_size -= 197; $original_filename = $filename; $filename =~ s/^\s+|\s+$//g ; $storage_name = md5_hex($filename."salt666".$filenumbe +r); open(UPLOADFILE, ">>", $upload_path.$storage_name ); chmod 0777, $upload_path.$storage_name; binmode UPLOADFILE; print UPLOADFILE $buffer; close UPLOADFILE; $first_hook = 0; }else{ open(DEBUG, ">>", $debug_path."abort_debug.txt" ); binmode DEBUG; print DEBUG "BR: "; print DEBUG "$bytes_read\n"; close DEBUG; open(UPLOADFILE, ">>", $upload_path.$storage_name ); binmode UPLOADFILE; print UPLOADFILE $buffer; close UPLOADFILE; if (($buffer eq '') == 1) { unlink($upload_path.$storage_name); open(DEBUG, ">>", $debug_path."abort_debug.txt" ); binmode DEBUG; print DEBUG "error file upload aborted\n"; close DEBUG; exit 0; } } } open(DEBUG, ">>", $debug_path."end_debug.txt" ); binmode DEBUG; print DEBUG "END\n#\n"; close DEBUG; print "Content-type: text/html\n\n END"; exit;

In reply to perl cgi scrpit killed by apache on client abort by pustka

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.