web-link-saver: remove multithread stuff from img-save.pl script due to huge mem leak
This commit is contained in:
@@ -4,7 +4,6 @@ use warnings "all";
|
|||||||
use strict;
|
use strict;
|
||||||
use Cache::Memcached;
|
use Cache::Memcached;
|
||||||
use URI::URL;
|
use URI::URL;
|
||||||
use threads;
|
|
||||||
|
|
||||||
my $HTINY = undef;
|
my $HTINY = undef;
|
||||||
my $HTINYS = undef;
|
my $HTINYS = undef;
|
||||||
@@ -40,8 +39,7 @@ my $IMAGEMAGICK = undef; # use on demand
|
|||||||
if ($^O ne 'cygwin') { # cygwin 2.882 64-bit has broken Image::Magick
|
if ($^O ne 'cygwin') { # cygwin 2.882 64-bit has broken Image::Magick
|
||||||
eval {
|
eval {
|
||||||
require Image::Magick;
|
require Image::Magick;
|
||||||
import Image::Magick qw(ping);
|
import Image::Magick;
|
||||||
return 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($@ eq '') {
|
if ($@ eq '') {
|
||||||
@@ -81,17 +79,27 @@ while ( 1 ) {
|
|||||||
} split(/\n/, $cachedump->{'hosts'}->{'127.0.0.1:11211'}->{"cachedump $slab $itemsamount"});
|
} split(/\n/, $cachedump->{'hosts'}->{'127.0.0.1:11211'}->{"cachedump $slab $itemsamount"});
|
||||||
|
|
||||||
foreach my $key (@keys) {
|
foreach my $key (@keys) {
|
||||||
next unless ($key =~ /^hcht_/);
|
|
||||||
next unless ($key =~ /^irssi_/);
|
next unless ($key =~ /^irssi_/);
|
||||||
|
next unless ($key =~ /^xchtlink_/);
|
||||||
|
|
||||||
my $url = $memd->get($key);
|
my $url = $memd->get($key);
|
||||||
my $t = threads->create('cdlfunc', $url);
|
cdlfunc($url);
|
||||||
$t->detach() if (defined($t)); # detach only if we succeed in creating thread :)
|
undef $url;
|
||||||
undef $t;
|
|
||||||
$memd->delete($key);
|
$memd->delete($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $slabinfo;
|
||||||
|
undef $slab;
|
||||||
|
undef $itemsamount;
|
||||||
|
undef $cachedump;
|
||||||
|
@keys = -1;
|
||||||
|
undef @keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $itemref;
|
||||||
$memd->disconnect_all;
|
$memd->disconnect_all;
|
||||||
|
undef $memd;
|
||||||
|
|
||||||
sleep(30);
|
sleep(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +120,13 @@ sub cdlfunc($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dlfunc($url, $savepath);
|
dlfunc($url, $savepath);
|
||||||
|
undef $savepath;
|
||||||
|
undef $fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $url;
|
||||||
|
undef $extension;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,10 +164,16 @@ sub dlfunc(@) {
|
|||||||
$rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i));
|
$rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i));
|
||||||
rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1);
|
rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $im;
|
||||||
|
undef $rename;
|
||||||
|
undef $format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $url;
|
||||||
|
undef $file;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,14 +186,12 @@ sub is_picture($) {
|
|||||||
eval {
|
eval {
|
||||||
my $http = HTTP::Tiny->new();
|
my $http = HTTP::Tiny->new();
|
||||||
$r = $http->request('HEAD', $url);
|
$r = $http->request('HEAD', $url);
|
||||||
undef $url;
|
|
||||||
undef $http;
|
undef $http;
|
||||||
};
|
};
|
||||||
} elsif (defined($HTINY)) {
|
} elsif (defined($HTINY)) {
|
||||||
eval {
|
eval {
|
||||||
my $http = HTTP::Tiny->new();
|
my $http = HTTP::Tiny->new();
|
||||||
$r = $http->request('HEAD', $url);
|
$r = $http->request('HEAD', $url);
|
||||||
undef $url;
|
|
||||||
undef $http;
|
undef $http;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -183,11 +200,14 @@ sub is_picture($) {
|
|||||||
foreach (split(/\n/, $r)) {
|
foreach (split(/\n/, $r)) {
|
||||||
next unless($_ =~ /Content\-Type: (.+)/);
|
next unless($_ =~ /Content\-Type: (.+)/);
|
||||||
my $h = ($1); chomp($h);
|
my $h = ($1); chomp($h);
|
||||||
|
$r = undef;
|
||||||
$r->{'success'} = 1;
|
$r->{'success'} = 1;
|
||||||
$r->{'headers'}->{'content-type'} = $h;
|
$r->{'headers'}->{'content-type'} = $h;
|
||||||
|
undef $h;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$r = undef;
|
||||||
$r->{'success'} = 0;
|
$r->{'success'} = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,6 +223,7 @@ sub is_picture($) {
|
|||||||
$r = undef;
|
$r = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $url;
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,3 +234,4 @@ sub urlencode($) {
|
|||||||
undef $urlobj;
|
undef $urlobj;
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user