You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Ruslan U. Zakirov" <cu...@wildgate.miee.ru> on 2003/10/21 09:28:59 UTC

Re: Getting new id with every calls with Apache::Session

        Hello.
Have you read `perldoc Apache::Session`? There is two examples.

perl@swanmail.com wrote:

>I'm getting a new id with every refresh click; so, how am I suppose to
>know it is the same session? Here's my code:
>
>#!/usr/bin/perl
>use Apache::Session::File;
>use strict;
>use warnings;
>
>my %session;
>my $sessId;
>
>#I'm suppose to put the session id at the undef
>#but how am i suppose to #know what it is the next time around?
>#tie %session, 'Apache::Session::File', undef,
># { Directory => '/tmp', LockDirectory =>'/tmp' };
>
>tie %session, 'Apache::Session::File';
>
What about third argument??? It have to be session_id if you wnat old 
one or undef if you want new.
So you have to store session_id somewhere on the client side!

>$sessId = $session{_session_id};
>print "Content-type: text/html\n\n";
>print "id: " . $sessId . "\n";
>
>...
>
>What am I doing wrong?
>
>thanks
>
>  
>




Re[2]: Getting new id with every calls with Apache::Session

Posted by "Mike P. Mikhailov" <mi...@sibtel.ru>.
Hello perl@swanmail.com,

Tuesday, October 21, 2003, 1:46:06 PM, you wrote:

psc> I made two calls to ties for a test and the server comsume alot of CPU and
psc> never return. So I don't know what is going on.

psc> ...
psc> print "Content-type: text/html\n\n";
psc> tie %session, 'Apache::Session::File', undef;
psc> $sessId = $session{_session_id};
psc> print "id: " . $sessId . "\n";

psc> #the prog get hung when I added this line
psc> tie %session, 'Apache::Session::File', $sessId;
psc> $sessId = $session{_session_id};
psc> print "id: " . $sessId . "\n";
psc> ...

psc> In any case, are you saying that I have to pass the sessionId to the
psc> client as a cookie as in the doc? If so, isn;t there a package that
psc> already wraps this up for me?

Take a look at the Apache::SessionManager, hope it help.

-- 
WBR, Mike P. Mikhailov

mailto: mike@sibtel.ru
ICQ:    280990142

Internet is a wonderful mechanism for making a fool of yourself in front of a very large audience


Re: Getting new id with every calls with Apache::Session

Posted by "Ruslan U. Zakirov" <cu...@wildgate.miee.ru>.
perl@swanmail.com wrote:

>I made two calls to ties for a test and the server comsume alot of CPU and
>never return. So I don't know what is going on.
>
>...
>print "Content-type: text/html\n\n";
>tie %session, 'Apache::Session::File', undef;
>$sessId = $session{_session_id};
>print "id: " . $sessId . "\n";
>
untie %session;
or
undef %session;
Apache session using locking mechanism so when you have touched session 
it's locked until you end up with it.

>
>#the prog get hung when I added this line
>tie %session, 'Apache::Session::File', $sessId;
>$sessId = $session{_session_id};
>print "id: " . $sessId . "\n";
>...
>
>In any case, are you saying that I have to pass the sessionId to the
>client as a cookie as in the doc?
>
Yes, pass to user, but there more ways then just Cookie.

>If so, isn;t there a package that
>already wraps this up for me?
>

Use next scheme for start:
    my %cookies = CGI::Cookie->fetch();
    $sid = ($cookies{'SID'} ? $cookies{'SID'}->value() : undef );
    eval {
        tie %session, 'Apache::Session:: ... ', $sid, {};
    };
    if ($@) {
 
        # If the session is invalid, create a new session.
        if ( $@ =~ /Object does not/i ) {
            tie %session, 'Apache::Session:: ... ', undef, {};
            undef $cookies{'SID'};
        }
        else {
            die "$@. Check that this directory's permissions are correct.";
        }
    }
    if ( !$cookies{'SID'} ) {
        my $cookie = new CGI::Cookie(
            -name  => 'SID',
            -value => $session{_session_id},
            -path  => '/',
        );
        $r->header_out('Set-Cookie', $cookie->as_string);
    }

>
>thanks
>
>
>  
>
>>        Hello.
>>Have you read `perldoc Apache::Session`? There is two examples.
>>
>>perl@swanmail.com wrote:
>>
>>    
>>
>>>I'm getting a new id with every refresh click; so, how am I suppose to
>>>know it is the same session? Here's my code:
>>>
>>>#!/usr/bin/perl
>>>use Apache::Session::File;
>>>use strict;
>>>use warnings;
>>>
>>>my %session;
>>>my $sessId;
>>>
>>>#I'm suppose to put the session id at the undef
>>>#but how am i suppose to #know what it is the next time around?
>>>#tie %session, 'Apache::Session::File', undef,
>>># { Directory => '/tmp', LockDirectory =>'/tmp' };
>>>
>>>tie %session, 'Apache::Session::File';
>>>
>>>      
>>>
>>What about third argument??? It have to be session_id if you wnat old
>>one or undef if you want new.
>>So you have to store session_id somewhere on the client side!
>>
>>    
>>
>>>$sessId = $session{_session_id};
>>>print "Content-type: text/html\n\n";
>>>print "id: " . $sessId . "\n";
>>>
>>>...
>>>
>>>What am I doing wrong?
>>>
>>>thanks
>>>
>>>
>>>
>>>      
>>>
>>
>>
>>    
>>



Re: Getting new id with every calls with Apache::Session

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2003-10-21 at 03:46, perl@swanmail.com wrote:
> I made two calls to ties for a test and the server comsume alot of CPU and
> never return. So I don't know what is going on.
> 
> ...
> print "Content-type: text/html\n\n";
> tie %session, 'Apache::Session::File', undef;
> $sessId = $session{_session_id};
> print "id: " . $sessId . "\n";
> 
> #the prog get hung when I added this line
> tie %session, 'Apache::Session::File', $sessId;
> $sessId = $session{_session_id};
> print "id: " . $sessId . "\n";
> ...

What's going on is that Apache::Session uses locking to prevent more
than one access to a single session at a time.  This is a bad idea for
most applications, and can be turned off if you use
Apache::Session::Flex with the NullLocker as your locking module.

> In any case, are you saying that I have to pass the sessionId to the
> client as a cookie as in the doc? If so, isn;t there a package that
> already wraps this up for me?

Yes and yes.  Take a look at Apache::SessionManager.

If that doesn't do it for you, look at CGI::Session.  It is much more
actively maintained than Apache::Session, and has better documentation
and better support for new users.

- Perrin

Re: Getting new id with every calls with Apache::Session

Posted by pe...@swanmail.com.
I made two calls to ties for a test and the server comsume alot of CPU and
never return. So I don't know what is going on.

...
print "Content-type: text/html\n\n";
tie %session, 'Apache::Session::File', undef;
$sessId = $session{_session_id};
print "id: " . $sessId . "\n";

#the prog get hung when I added this line
tie %session, 'Apache::Session::File', $sessId;
$sessId = $session{_session_id};
print "id: " . $sessId . "\n";
...

In any case, are you saying that I have to pass the sessionId to the
client as a cookie as in the doc? If so, isn;t there a package that
already wraps this up for me?

thanks


>         Hello.
> Have you read `perldoc Apache::Session`? There is two examples.
>
> perl@swanmail.com wrote:
>
>>I'm getting a new id with every refresh click; so, how am I suppose to
>>know it is the same session? Here's my code:
>>
>>#!/usr/bin/perl
>>use Apache::Session::File;
>>use strict;
>>use warnings;
>>
>>my %session;
>>my $sessId;
>>
>>#I'm suppose to put the session id at the undef
>>#but how am i suppose to #know what it is the next time around?
>>#tie %session, 'Apache::Session::File', undef,
>># { Directory => '/tmp', LockDirectory =>'/tmp' };
>>
>>tie %session, 'Apache::Session::File';
>>
> What about third argument??? It have to be session_id if you wnat old
> one or undef if you want new.
> So you have to store session_id somewhere on the client side!
>
>>$sessId = $session{_session_id};
>>print "Content-type: text/html\n\n";
>>print "id: " . $sessId . "\n";
>>
>>...
>>
>>What am I doing wrong?
>>
>>thanks
>>
>>
>>
>
>
>
>



-----------------------------------------
eMail solutions by 
http://www.swanmail.com