Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Apache::Session problem update...

by Anonymous Monk
on Dec 29, 2002 at 00:17 UTC ( #222820=note: print w/replies, xml ) Need Help??


in reply to Apache::Session problem update...

If you turned warnings on, you would see a warning about "variable cannot remain shared". The three basic solutions are to pass the session keys explicitly into every function, change my to our, or use the vars pragma to declare variables instead of using my.

OK, so that is the solution. What is the problem? That is a little more complex to explain.

Here is what Apache::Registry does. The first time your run your script it takes your CGI script, sticks a function around it, and calls eval. The second time it calls that function. The problem is that the functions in your script have global names, but the my variables that they are sharing with the rest of your script are private to the invocation of the outer wrapper function. So if you call the outer wrapper function twice (ie access the page twice), on the second call all of your functions are accessing the my variables from the first time you loaded that page.

If this confuses you, then review the code example at Re (tilly) 9: Why are closures cool? carefully and see if you an understand what it does. Replace the entire contents of outer() by your script, get rid of the anonymous functions that are meant to show you what is happening, and you have what is going wrong with your script.

If you still have trouble seeing it, just take my word that the problem is subtle and is basically impossible to come up with a really good fix to.

In that light, the three solutions correspondingly are to stop trying to share a private variable, make the private variable accessed actually be a global variable, and just plain make accessing a global variable OK.

Replies are listed 'Best First'.
Re: Re: Apache::Session problem update...
by iguanodon (Priest) on Dec 29, 2002 at 13:55 UTC
    If you turned warnings on, you would see a warning about "variable cannot remain shared".

    If he is running this under mod_perl, that is. I don't see mod_perl mentioned in the original post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://222820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2022-12-10 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?