| File | /usr/share/perl5/CGI/Session/Driver/mysql.pm |
| Statements Executed | 26 |
| Total Time | 0.0390965 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2 | 2 | 2 | 43µs | 82µs | CGI::Session::Driver::mysql::table_name |
| 1 | 1 | 1 | 39µs | 57µs | CGI::Session::Driver::mysql::init |
| 1 | 1 | 1 | 30µs | 38.5ms | CGI::Session::Driver::mysql::store |
| 0 | 0 | 0 | 0s | 0s | CGI::Session::Driver::mysql::BEGIN |
| 0 | 0 | 0 | 0s | 0s | CGI::Session::Driver::mysql::_mk_dsnstr |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | package CGI::Session::Driver::mysql; | |||
| 2 | ||||
| 3 | # $Id: mysql.pm 447 2008-11-01 03:46:08Z markstos $ | |||
| 4 | ||||
| 5 | 3 | 164µs | 55µs | use strict; # spent 15µs making 1 call to strict::import |
| 6 | 3 | 41µs | 14µs | use Carp; # spent 71µs making 1 call to Exporter::import |
| 7 | 3 | 520µs | 173µs | use CGI::Session::Driver::DBI; # spent 16µs making 1 call to UNIVERSAL::import |
| 8 | ||||
| 9 | 1 | 11µs | 11µs | @CGI::Session::Driver::mysql::ISA = qw( CGI::Session::Driver::DBI ); |
| 10 | 1 | 500ns | 500ns | $CGI::Session::Driver::mysql::VERSION = '4.38'; |
| 11 | ||||
| 12 | sub _mk_dsnstr { | |||
| 13 | my ($class, $dsn) = @_; | |||
| 14 | unless ( $class && $dsn && ref($dsn) && (ref($dsn) eq 'HASH')) { | |||
| 15 | croak "_mk_dsnstr(): usage error"; | |||
| 16 | } | |||
| 17 | ||||
| 18 | my $dsnstr = $dsn->{DataSource}; | |||
| 19 | if ( $dsn->{Socket} ) { | |||
| 20 | $dsnstr .= sprintf(";mysql_socket=%s", $dsn->{Socket}); | |||
| 21 | } | |||
| 22 | if ( $dsn->{Host} ) { | |||
| 23 | $dsnstr .= sprintf(";host=%s", $dsn->{Host}); | |||
| 24 | } | |||
| 25 | if ( $dsn->{Port} ) { | |||
| 26 | $dsnstr .= sprintf(";port=%s", $dsn->{Port}); | |||
| 27 | } | |||
| 28 | return $dsnstr; | |||
| 29 | } | |||
| 30 | ||||
| 31 | ||||
| 32 | # spent 57µs (39+19) within CGI::Session::Driver::mysql::init which was called
# once (39µs+19µs) by CGI::Session::Driver::new at line 38 of /usr/share/perl5/CGI/Session/Driver.pm | |||
| 33 | 1 | 1µs | 1µs | my $self = shift; |
| 34 | 1 | 1µs | 1µs | if ( $self->{DataSource} && ($self->{DataSource} !~ /^dbi:mysql/i) ) { |
| 35 | $self->{DataSource} = "dbi:mysql:database=" . $self->{DataSource}; | |||
| 36 | } | |||
| 37 | ||||
| 38 | 1 | 800ns | 800ns | if ( $self->{Socket} && $self->{DataSource} ) { |
| 39 | $self->{DataSource} .= ';mysql_socket=' . $self->{Socket}; | |||
| 40 | } | |||
| 41 | 1 | 35µs | 35µs | return $self->SUPER::init(); # spent 19µs making 1 call to CGI::Session::Driver::DBI::init |
| 42 | } | |||
| 43 | ||||
| 44 | # spent 38.5ms (30µs+38.5) within CGI::Session::Driver::mysql::store which was called
# once (30µs+38.5ms) by CGI::Session::flush at line 253 of /usr/share/perl5/CGI/Session.pm | |||
| 45 | 1 | 1µs | 1µs | my $self = shift; |
| 46 | 1 | 3µs | 3µs | my ($sid, $datastr) = @_; |
| 47 | 1 | 700ns | 700ns | croak "store(): usage error" unless $sid && $datastr; |
| 48 | ||||
| 49 | 1 | 2µs | 2µs | my $dbh = $self->{Handle}; |
| 50 | 1 | 38.3ms | 38.3ms | $dbh->do("INSERT INTO " . $self->table_name . # spent 38.5ms making 1 call to DBI::db::do
# spent 40µs making 1 call to CGI::Session::Driver::mysql::table_name |
| 51 | " ($self->{IdColName}, $self->{DataColName}) VALUES(?, ?) ON DUPLICATE KEY UPDATE $self->{DataColName} = ?", | |||
| 52 | undef, $sid, $datastr, $datastr) | |||
| 53 | or return $self->set_error( "store(): \$dbh->do failed " . $dbh->errstr ); | |||
| 54 | 1 | 3µs | 3µs | return 1; |
| 55 | } | |||
| 56 | ||||
| 57 | ||||
| 58 | # spent 82µs (43+38) within CGI::Session::Driver::mysql::table_name which was called 2 times, avg 41µs/call:
# once (21µs+20µs) by CGI::Session::Driver::DBI::retrieve at line 68 of /usr/share/perl5/CGI/Session/Driver/DBI.pm
# once (22µs+18µs) by CGI::Session::Driver::mysql::store at line 50 | |||
| 59 | 2 | 2µs | 900ns | my $self = shift; |
| 60 | ||||
| 61 | 2 | 43µs | 21µs | return $self->SUPER::table_name(@_); # spent 38µs making 2 calls to CGI::Session::Driver::DBI::table_name, avg 19µs/call |
| 62 | } | |||
| 63 | ||||
| 64 | 1 | 4µs | 4µs | 1; |
| 65 | ||||
| 66 | __END__; | |||
| 67 | ||||
| 68 | =pod | |||
| 69 | ||||
| 70 | =head1 NAME | |||
| 71 | ||||
| 72 | CGI::Session::Driver::mysql - CGI::Session driver for MySQL database | |||
| 73 | ||||
| 74 | =head1 SYNOPSIS | |||
| 75 | ||||
| 76 | $s = new CGI::Session( 'driver:mysql', $sid); | |||
| 77 | $s = new CGI::Session( 'driver:mysql', $sid, { DataSource => 'dbi:mysql:test', | |||
| 78 | User => 'sherzodr', | |||
| 79 | Password => 'hello' }); | |||
| 80 | $s = new CGI::Session( 'driver:mysql', $sid, { Handle => $dbh } ); | |||
| 81 | ||||
| 82 | =head1 DESCRIPTION | |||
| 83 | ||||
| 84 | B<mysql> stores session records in a MySQL table. For details see L<CGI::Session::Driver::DBI|CGI::Session::Driver::DBI>, its parent class. | |||
| 85 | ||||
| 86 | It's especially important for the MySQL driver that the session ID column be | |||
| 87 | defined as a primary key, or at least "unique", like this: | |||
| 88 | ||||
| 89 | CREATE TABLE sessions ( | |||
| 90 | id CHAR(32) NOT NULL PRIMARY KEY, | |||
| 91 | a_session TEXT NOT NULL | |||
| 92 | ); | |||
| 93 | ||||
| 94 | To use different column names, change the 'create table' statement, and then simply do this: | |||
| 95 | ||||
| 96 | $s = new CGI::Session('driver:mysql', undef, | |||
| 97 | { | |||
| 98 | TableName=>'session', | |||
| 99 | IdColName=>'my_id', | |||
| 100 | DataColName=>'my_data', | |||
| 101 | DataSource=>'dbi:mysql:project', | |||
| 102 | }); | |||
| 103 | ||||
| 104 | or | |||
| 105 | ||||
| 106 | $s = new CGI::Session('driver:mysql', undef, | |||
| 107 | { | |||
| 108 | TableName=>'session', | |||
| 109 | IdColName=>'my_id', | |||
| 110 | DataColName=>'my_data', | |||
| 111 | Handle=>$dbh, | |||
| 112 | }); | |||
| 113 | ||||
| 114 | =head2 DRIVER ARGUMENTS | |||
| 115 | ||||
| 116 | B<mysql> driver supports all the arguments documented in L<CGI::Session::Driver::DBI|CGI::Session::Driver::DBI>. In addition, I<DataSource> argument can optionally leave leading "dbi:mysql:" string out: | |||
| 117 | ||||
| 118 | $s = new CGI::Session( 'driver:mysql', $sid, {DataSource=>'shopping_cart'}); | |||
| 119 | # is the same as: | |||
| 120 | $s = new CGI::Session( 'driver:mysql', $sid, {DataSource=>'dbi:mysql:shopping_cart'}); | |||
| 121 | ||||
| 122 | =head2 BACKWARDS COMPATIBILITY | |||
| 123 | ||||
| 124 | As of V 4.30, the global variable $CGI::Session::MySQL::TABLE_NAME cannot be used to set the session | |||
| 125 | table's name. | |||
| 126 | ||||
| 127 | This is due to changes in CGI::Session::Driver's new() method, which now allows the table's name to be | |||
| 128 | changed (as well as allowing both the 'id' column name and the 'a_session' column name to be changed). | |||
| 129 | ||||
| 130 | See the documentation for CGI::Session::Driver::DBI for details. | |||
| 131 | ||||
| 132 | In particular, the new syntax for C<new()> applies to all database drivers, whereas the old - and bad - | |||
| 133 | global variable method only applied to MySQL. | |||
| 134 | ||||
| 135 | Alternately, call $session -> table_name('new_name') just after creating the session object if you wish to | |||
| 136 | change the session table's name. | |||
| 137 | ||||
| 138 | =head1 LICENSING | |||
| 139 | ||||
| 140 | For support and licensing see L<CGI::Session|CGI::Session>. | |||
| 141 | ||||
| 142 | =cut |