root/Apache-Session-PHP/trunk/lib/Apache/Session/Store/PHP.pm

Revision 555 (checked in by miyagawa, 19 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package Apache::Session::Store::PHP;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.01;
6
7 use Apache::Session::File;
8
9 use Fcntl qw(:flock);
10 use IO::File;
11
12 sub new {
13     my $class = shift;
14     bless {}, $class;
15 }
16
17 sub _file {
18     my($self, $session) = @_;
19     my $directory = $session->{args}->{SavePath} || '/tmp';
20     return $directory.'/sess_'.$session->{data}->{_session_id};
21 }
22
23 sub insert {
24     my($self, $session) = @_;
25     $self->_write($session, 1);
26 }
27
28 sub update {
29     my($self, $session) = @_;
30     $self->_write($session, 0);
31 }
32
33 sub _write {
34     my($self, $session, $check) = @_;
35
36     if ($check && -e $self->_file($session)) {
37         die "Object already exists in the data store";
38     }
39
40     my $fh = IO::File->new($self->_file($session), O_RDWR|O_CREAT)
41         or die "Could not open file: $!";
42     flock $fh, LOCK_EX;
43     $fh->print($session->{serialized});
44     $fh->close;
45 }
46
47 sub materialize {
48     my($self, $session) = @_;
49     my $file = $self->_file($session);
50     -e $file or die "Object does not exist in the data store";
51
52     my $fh = IO::File->new($self->_file($session), O_RDWR|O_CREAT)
53         or die "Could not open file: $!";
54     flock $fh, LOCK_EX;
55     while (<$fh>) {
56         $session->{serialized} .= $_;
57     }
58     close $fh;
59 }
60
61 sub remove {
62     my($self, $session) = @_;
63     my $file = $self->_file($session);
64     unlink $file if -e $file;
65 }
66
67 1;
68 __END__
69
70 =head1 NAME
71
72 Apache::Session::Store::PHP - writes to PHP4 builtin session files
73
74 =head1 SYNOPSIS
75
76 B<DO NOT USE THIS MODULE DIRECTLY>
77
78 =head1 AUTHOR
79
80 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
81
82 This library is free software; you can redistribute it and/or modify
83 it under the same terms as Perl itself.
84
85 =head1 SEE ALSO
86
87 L<Apache::Session::PHP>
88
89 =cut
Note: See TracBrowser for help on using the browser.