#!/usr/local/bin/perl use strict; use Time::HiRes qw( time ); use CGI; ################### MAIN ###################### { my $time_start = time; my $cgi = new CGI; print $cgi->header(); print $cgi->start_html(); open(REPORT, ">./report.out"); my $file = $cgi->upload("upload_file"); if (!$file && $cgi->cgi_error) { print $cgi->header(-status=>$cgi->cgi_error); exit 0; } elsif ($file) { use Data::Dumper; my $upload_info = $cgi->uploadInfo($file); print Dumper($upload_info); if (!fork()) { # do this stuff in child process... # get rid of STDOUT so that CGI won't # have to hold on to this (child) process until # it's done. open(STDOUT, ">/dev/null"); my ($local_file) = ($file =~ m|[\\/]+([^\\/]+)$|); open (OUTFILE,">./$local_file"); my ($buffer, $bytesread); while (<$file>) { print OUTFILE $_; } close (OUTFILE); my $time_finish = time; my $child_time = $time_finish - $time_start; print REPORT "Child time: $child_time\n"; # note: this will also flush the buffer, # which may any lines printed to this handle # before the fork() to duplicate! close (REPORT); exit; } print "File '$file' uploaded successfully!

Saved in '$file'. "; } print $cgi->start_multipart_form(); print $cgi->filefield(-name=>'upload_file', -default=>'starting value', -size=>50, -maxlength=>80); print $cgi->submit(-value => 'Submit!'); print $cgi->end_form; my $time_finish = time; my $time_parent = $time_finish - $time_start; print REPORT "Time Start: $time_start\n"; print REPORT "Parent time: $time_parent\n"; # I may end up closing this before even the child process # has finished writing to it? close REPORT; exit; }