Okay. I'm poor programmer. I'm dumb. OKAY, I'M AN IDIOT. I agree.
But now, PLEASE, point me WHY Apache::Session does NEVER get destroyed
it the sample handler.
Have I told you that I'm poor programmer, don't know Perl at all and
overall dumb and cannot even type?
JUST POINT ME TO MY ERROR!
PLEASE NO clever ideas of reread of mail archive, for over an hour I'm
trying to get my error.
=== cut handler.pl ===
#!/usr/bin/perl
# $Id: handler.pl,v 1.3 2000/01/14 19:42:16 tarkhil Exp $
#
$ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/
or die "GATEWAY_INTERFACE not Perl!";
use Apache::Registry;
use Apache::Status;
use DBI;
use Socket;
use Carp qw(cluck confess);
use Apache::DBI ();
package HTML::Mason;
use HTML::Mason;
use strict;
{
package HTML::Mason::Commands;
use Apache::Registry;
use Apache::Status;
use DBI;
use Apache::DBI ();
use Apache::Session::DBI;
use Net::SNPP;
use Apache::AuthDBI;
use MIME::Head;
use Mail::Send;
use Mail::Mailer;
use Mail::Header;
use Image::Size 'html_imgsize';
use HTTP::Status;
use Net::POP3;
#use Apache::SizeLimit;
#$Apache::SizeLimit::MAX_PROCESS_SIZE = 10000; # 10000kB = 10MB
Apache::DBI->connect_on_init
("DBI:mysql:mail2pager",
"tarkhil", "cypurcad",
{ RaiseError => 1, PrintError => 1, AutoCommit => 1, }
);
}
my $parser = new HTML::Mason::Parser
(
allow_globals => [qw($dbh %session %pagers %mailserv @mssort)]
);
my $interp = new HTML::Mason::Interp
(parser=>$parser,
data_dir => "/usr/local/www/tmp",
comp_root => "/usr/local/www");
$interp->set_global(dbh=>DBI->connect
("DBI:mysql:mail2pager",
"tarkhil", "cypurcad",
{ RaiseError => 1, PrintError => 1,
AutoCommit => 1, }
));
$interp->set_global('%pagers'=>
(
0 => "Выберите оператора",
1 => "Мобил Телеком",
2 => "Астрапейдж",
3 => "Радиоскан",
4 => "Континенталь",
5 => "Вессолинк",
6 => "Радиопейдж",
7 => "Вессотел",
8 => "Мульти-Пейдж",
9 => "Информ-Экском",
10 => "Альфаком",
1000 => "Mail2Phone Free (МТС)",
1001 => "МТС/BeeLine",
101 => "СТС-Пейдж",
102 => "Вессолинк (Псков)",
103 => "Калужская сотовая",
104 => "Алком Электроникс (Hовокузнецк)",
105 => "Алком Электроникс (Кемерово)",
106 => "Экском Петербург",
107 => "Мтелеком Спб.",
11 => "Роза Мира",
12 => "ВС Телеком",
13 => 'ЭКСПРЕСС (Спб)',
200 => 'Серком (Хабаровск)',
));
$interp->set_global('%mailserv'=>
(
'pop.mail.ru' => 'MAIL.RU',
'chat.ru' => 'CHAT.RU',
'mail.express.ru' => 'EXPRESS.RU',
'other' => '(другом)',
));
$interp->set_global('@mssort'=>
(
'other', 'chat.ru', 'mail.express.ru', 'pop.mail.ru'
));
my $ah = new HTML::Mason::ApacheHandler (interp=>$interp,
output_mode=>'batch');
chown ( 60001, 60001, $interp->files_written );
use Apache::Cookie;
sub handler {
my ($r) = @_;
# Handle only what we understand
return -1 if $r->method !~ /^(GET|POST|HEAD)$/;
return -1
if defined($r->content_type) && $r->content_type !~ m|^text/|io;
my ($port, $addr) = Socket::sockaddr_in($r->connection->local_addr);
# WebDAV will do everything on itself
return -1 if $port == 8000;
local $SIG{ALRM} = sub {Carp::confess "Alarm ";};
alarm 20;
my $cook = Apache::Cookie->new($r);
my $cookie = $cook->get('SESSION_ID');
# Unless exists session_id, clean it!
my $dbh = DBI->connect
("DBI:mysql:mail2pager",
"tarkhil", "cypurcad",
{ RaiseError => 1, PrintError => 1,
AutoCommit => 1, }
);
my $sth = $dbh->prepare_cached(q{
select id from sessions
where id = ?
});
$sth->execute($cookie);
my $rses;
$rses = $sth->fetchall_arrayref();
if (scalar @$rses == 0) {
$cookie = undef;
}
my %session;
tie %session, 'Apache::Session::DBI', $cookie,
{ DataSource => 'dbi:mysql:mail2pager', UserName => 'tarkhil',
Password => 'cypurcad'};
# warn "\[$$\] Tied session $session{_session_id}\n";
$cook->set(-name => "SESSION_ID", -value => $session{_session_id})
if ( !$cookie );
local *HTML::Mason::Command::session = \%session;
my $res = $ah->handle_request($r);
# warn "\[$$\] Going to untie session $session{_session_id}\n";
alarm 2;
untie %session;
# warn "\[$$\] Session untied\n";
alarm 0;
return $res;
}
1;
=== cut handler.pl ===
=== from httpd.conf ===
PerlRequire /usr/local/www/lib/handler.pl
DefaultType text/html
<Location />
SetHandler perl-script
PerlHandler HTML::Mason
</Location>
=== httpd.conf ===
Configuration of my server, just in case:
Server: Apache/1.3.9 (Unix) DAV/0.9.14 mod_perl/1.21 rus/PL29.2
Apache::Session is latest from CPAN.
--
Alexander B. Povolotsky [ICQ 18277558]
[2:5020/145] [[EMAIL PROTECTED]]