perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Michael" <jo...@acadiacom.net>
Subject too many files open
Date Mon, 03 Dec 2001 16:14:51 GMT
Hi
I use the perl sub below to create thumbs with image magick on my mod perl server and
never really had any problems with it.  I put it on another server and after
a short while it froze up the server with this error.
too many files open.

It is running under a mod-perl environment because in doing so I am also able to rename images
at the same time.
I know that because it is running under a mod perl environment, the lifetime of the script
is until roboot of server or
restart of apache.


The freeze happend on one of the lines in this sub so I'm thinking I'm not doing
something right and leaving files open.
I don't think this is a result of the problem with the server.

I would appreciate if someone would look at it and tell me if it is ok or not or give me some
suggestions to prevent this problem in the future so that I can continue to run it in mod-perl.

Perlmagick claims that it handles all of the file handling.


sub is called like so:
# Call to build the thumbs here
if ($build_thumbs){&build_thumbs($folder,$working_dir,$thumb_pattern);}


#####################################
sub build_thumbs {
my ($folder,$base_dir,$thumb_pattern) = @_;
my $current_dir = cwd;
my $working_dir = join("/",$base_dir, $folder);

print qq~<p>Building Thumbs in Folder: $folder</p>\n~;
chdir ($working_dir) || die "cannot cd $working_dir ($!)";
my @image_array = glob("*.jpg");
my @images = ();
foreach (@image_array) {
    unless ( $_ =~ /$thumb_pattern/i ) {
    push(@images, $_);
}  }
my $pic;
my $num_thumbs = @images;

foreach $pic (@images){
    my $image = Image::Magick->new(magick=>'JPEG');
    my $file = join("/",$working_dir, $pic);
    open(DATA, "$file") || die "$file $!";
        $image->Read(file=>DATA);
    close(DATA);

## MAKE THUMB HERE ##
my ($width, $height, $size, $format) = split(/,/,$image->Ping($file));
my $rotated = 0;
if ($width > $height){
    $image->Rotate(degrees=>'90');
    $rotated = 1;
}
$image->Resize(geometry=>'55',filter=>'Gaussian', blur=>'.5');
if ($rotated){
    $image->Rotate(degrees=>'-90');
}
## END MAKE THUMB HERE ##

my $out_file = join("/",$working_dir, "$thumb_pattern$pic");

open(DATA, ">$out_file");
    $image->Write(file=>DATA,filename=>$out_file);
close(DATA);

undef @$image;
}

undef $image;
chdir ($current_dir);

print qq~<p>Built <b>$num_thumbs</b> Thumbs in Folder: $folder</p>\n~;
}
############################################################################
###############

THanks in advance
John Michael



Mime
View raw message