see we are using Catalyst and it run under mod_perl2. we're planning to
use Geo::IP in our Controller.
I'm wondering which code is better as following.
1)
use vars qw/$geo_ip/;
sub ip_to_location {
my ( $ip ) = @_;
$geo_ip ||= Geo::IP->open("/usr/local/share/GeoIP/GeoLiteCity.dat",
GEOIP_STANDARD);
my $record = $geo_ip->record_by_addr($ip);
return unless $record;
return ( $record->country_code, $record->city,
$record->country_name, $record->region_name );
}
2)
use vars qw/$geo_ip/;
$geo_ip = Geo::IP->open("/usr/local/share/GeoIP/GeoLiteCity.dat",
GEOIP_STANDARD);
sub ip_to_location {
my ( $ip ) = @_;
my $record = $geo_ip->record_by_addr($ip);
return unless $record;
return ( $record->country_code, $record->city,
$record->country_name, $record->region_name );
}
I'm wondering in which way the $geo_ip is sharable through the threads.
we are using "server/mpm/prefork"
Thanks.
--
Fayland Lam // http://www.fayland.org/
Foorum based on Catalyst // http://www.foorumbbs.com/