LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2004, 06:16 AM   #1
hcubed
LQ Newbie
 
Registered: Sep 2003
Posts: 9

Rep: Reputation: 0
Forking in Perl on Apache webserver


I'm currently running Apache 2.0 on Slackware 9.0. I currently have a link called "Fetch" on my webpage that will run a specific function. This function is designed to fork and in the parent print out some garbage about what the function is doing and in the child execute a system command (in this case its going to zip up some files, send it to the user, and then delete the zip file). I have everything working except for the very last part (sending the file to the user). I don't think I'm sending the file to STDOUT, but I can't find anything in the error_log. Any ideas? The function is below so you can better understand what I have done so far. Thanks. (Oh yeah, I'm using the Apache::MP3 module so that's where some of the those weird functions are coming from).

sub fetch_archive {
my $self = shift;
my $r = $self->r;
my $path = "\"/usr/website/music" . $r->uri . "\"";
my $random = $r->uri;
my @fileholder;
my $attachment;

$random =~ /\/.+\/(.+)\//; #gets latter part of path for filename
$random = $1;
$random =~ s/ //g;
$random = $random . rand() . ".zip"; #creates random filename

if(!fork)
{
sleep(5); #pauses child so parent executes first
close(STDIN); close(STDOUT); close(STDERR);
`zip -0 -r -j -9 /usr/website/realdocs/$random $path`; #zip files
open (FILE, "</usr/website/realdocs/$random");
print STDOUT header("Content-Length: " . (-s "/usr/website/realdocs/" . $random));
print STDOUT header("Content-type: application/octet-stream");
print STDOUT header("Content-disposition: $attachment filename={$random}");
print STDOUT header("Content-Transfer-Encoding: binary");

print STDOUT $_ while ( read( FILE, $_, 1024 ) ); #send to client
close FILE;

`rm /usr/website/realdocs/$random`; #delete file

exit;
}
else
{
$self->r->content_type( $self->html_content_type );
return Apache::OK if $self->r->header_only;

print start_html(
-lang => $self->lh->language_tag,
-title => $self->x('Downloading'),
-dir => $self->lh->direction,
-head => meta({-http_equiv => 'Content-Type',
-content => 'text/html; charset='
. $self->html_content_type
}),
);

print $self->x("Zipping files for download...This may take up to 5 minutes."), br();
print $self->x("A dialog box will popup automatically when the file is ready for download."), br();
print $self->x("In the mean time you may go back and continue using the site.");
print end_html();

exit;
}
return Apache::OK;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl forking and memory allocation barkers Linux - Software 4 04-27-2005 06:04 AM
Uploading files to webserver in perl ? zulfilee Linux - Software 2 02-07-2005 11:07 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
Apache Webserver 403 Forbidden Errors (User not in apache group?) Mankind75 Mandriva 4 07-08-2004 05:30 AM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration