Re: [PHP4BETA] Re: PHP4 Session Management

From: Date: Mon, 03 Apr 2000 16:29:47 +0000
Subject: Re: [PHP4BETA] Re: PHP4 Session Management
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-13045@lists.php.net to get a copy of this message
Ofcource, and these are all well known problems in this area. But if you have a smart load balancer it will balance the connections (persistent) out over the machines based on a weight & active connection table. This balances out nicely enough for just about any system. Also the fact that https etc require persistent connections make this very tempting. But you are right, requests wont be load balanced, just connections. in 98% + of the cases this is good enough, and by far easier to maintain. If one would go for a central DB, this will become the bottleneck of the whole system, and limit your scalability, and provide a new single point of failure, eg the DB. But if those are prices u are willing to pay, then a DB stored session is a good alternative :) -- Chris Michael Nino wrote: > Thank you for your reply. I am pleased to hear of alternative > implementations. Here is what I think. Establishing a persistent > connection as you explain would load balance "sessions" rather than > "requests". Moreover, what happens if the connection goes down-- the > session is then lost because the server is gone. A centralized > database would alleviate this by picking up the session from a > different server servicing the dropped request.thanks!againmichael > > -----Original Message----- > From: Chris Chabot [mailto:chabotc@reviewboard.com] > Sent: Monday, April 03, 2000 7:09 AM > To: Michael Nino; php4beta@lists.php.net > Subject: Re: [PHP4BETA] Re: PHP4 Session Management > > Session management will work perfectly using the disk method > as long as you configure your hardware (or software based, > such as LVS (www.linuxvirtualserver.org)) for persistent > connections. This way a client will always hit the same box > in the session, thus enabling consitent session management. > This (persistent connection config) btw is also needed if > you ever want to do https, or any other server persistent > actions. > > In my experiance most hardware & software based load > balancing tools are able to do persistent connections. in > LVS it would mean adding '-p 1800' to the cluster creation > line. (without quotes) > > Hope this was of some help > > -- Chris Chabot > > Michael Nino wrote: > > > > > > > Here's a question along the same lines. What if you have > > several webservers-- all processing PHP documents AND > > hardware is load balancing between them, then what is the > > preferred way to manage sessions? Centralized MySQL > > database? > > > > m > > > > -----Original Message----- > > From: Brendan W. McAdams [mailto:brendan@plexmedia.com] > > Sent: Saturday, April 01, 2000 3:04 PM > > To: Hector Lucero > > Cc: php4beta@lists.php.net; php3@lists.php.net > > Subject: [PHP4BETA] Re: PHP4 Session Management > > > > no problem; I'm CCing this to the list in case anyone else > > cares to learn > > from it. > > > > >When you create a session, is that variable available > > throughout all pages? > > > > The session variable is available to all pages that create > > a session and as > > long as your session cookie is valid - the cookie by > > default expires when > > you close your browser. You need to declare a start of > > session on each page > > (see my previous post for more on that). > > > > Variables themselves ONLY go from page to page if you > > specifically tell your > > session to save them (see session_register in my last > > post) -- if you took > > all your variables it would take alot of disk space and > > memory so PHP just > > takes what you tell it to. > > > > >If you are submitting with an anchor i.e. a link, is that > > session variable > > available to other pages? > > > > Yes, two ways to do this: > > 1) Set the page you are linking to to start a session and > > find out what your > > session_id is. > > 2) link with a ?PHPSESSID=$PHPSESSID which passes your > > session ID > > automatically. > > > > >Can you give me an example of how to create a session > > since I have failed > > so far. > > > > Again I reccomend Julie Meloni's HotWired Webmonkey > > tutorial at: > > > > ttp://hotwired.lycos.com/webmonkey/00/05/index2a.html?tw=programming > > > > But here's my quick take on it using your examples pasted, > > now fixed for PHP > > Sessions (and with some of my own coding style applied, > > please forgive me): > > > > test.php > > > > <? > > echo "<html><body>"; > > echo "<form method=post action=test1.php>"; > > echo "<table><tr>"; > > echo "<td>Userid: </td><td><input type=text > > name=userid></td>"; > > echo "<td colspan=2><input type=submit > > value=\"Submit\">"; > > > > echo "</tr></table>"; > > echo "</body></html>"; > > ?> > > > > test1.php > > > > <? > > session_start(); > > session_register("user"); > > $user = $userid; > > echo "<html><body>"; > > echo "<form method=pos action=test2.php>"; > > echo "<input type=submit value=\"Submit\">"; > > echo "</form>"; > > echo "</body></html>"; > > ?> > > > > test2.php > > > > <? > > session_start(); // here's your problem - you need to pull > > the session up > > again to have access to its variables. > > > > // at this point $user was pulled out of the session cache > > on the server > > > > if (!$user) { // something happened, and for some reason > > the variable didnt > > save. > > > > echo("Error! Variable not found?"); > > > > exit(); // go bye-bye! > > > > } else { > > > > echo "<html><body>"; > > echo "User: $user"; // $user was pulled from the > > session ,we hope > > echo "</body></html>"; > > > > } > > > > ?> > > > > hope this helps. > > > > -brendan > > > > ----- > > Brendan W. McAdams | email: > > brendan@plexmedia.com > > Programmer/Systems Administrator | office: (305)377-2880 > > Plexus InterActive | pager: > > (305)277-4879 > > http://www.plexmedia.com | cell phone: > > (305)401-7313 > > > > "Always listen to the experts - they'll tell you what > > can't be done and why. > > Then do it." > > -Robert A. Heinlein > > ----- Original Message ----- > > From: "Hector Lucero" <hql@pacbell.net> > > To: <brendan@plexmedia.com> > > Sent: Saturday, April 01, 2000 4:18 PM > > Subject: PHP4 Session Management > > > > Hi,, > > > > Excuse me for sending you an email being a total > > stranger. I saw your > > response to one of the session emails in the php list. I > > am new to PHP > > and do not know how to create a session. Could you > > enlighten me a bit > > on the subject. I am using php4. > > > > * When you create a session, is that variable available > > throughout > > all pages? > > * If you are submitting with an anchor i.e. a link, is > > that session > > variable available to other pages? > > * Can you give me an example of how to create a session > > since I have > > failed so far. > > > > Note: This is what I have been doing and when I try to > > see the variable > > in other pages I dont get anything in test2.php. Am I > > doing something > > wrong? > > > > Thanks a million; > > > > Hector > > > > test.php > > > > <? > > echo "<html><body>"; > > echo "<form method=post action=test1.php>"; > > echo "<table><tr>"; > > echo "<td>Userid: </td><td><input type=text > > name=userid></td>"; > > echo "<td colspan=2><input type=submit > > value=\"Submit\">"; > > > > echo "</tr></table>"; > > echo "</body></html>"; > > ?> > > > > test1.php > > > > <? > > session_start(); > > session_register("user"); > > $user = $userid; > > echo "<html><body>"; > > echo "<form method=pos action=test2.php>"; > > echo "<input type=submit value=\"Submit\">"; > > echo "</form>"; > > echo "</body></html>"; > > ?> > > > > test2.php > > > > <? > > echo "<html><body>"; > > echo "User: $user"; > > echo "</body></html>"; > > ?> > > > > > > > > > > -- > > PHP 4.0 Beta Mailing List > > <http://www.php.net/version4/> > > To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net > > > > For additional commands, e-mail: > > php4beta-help@lists.php.net > > To contact the list administrators, e-mail: > > php4beta-admin@lists.php.net >

« previous php.version4 (#13045) next »