Re: Persistent state applications

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, May 17, 2008 at 3:34 PM, James Colannino <james@xxxxxxxxxxxxx> wrote:
> Hey everyone!  I'm very new to PHP, and had a somewhat general question
> (forgive me if it's too broad in scope.)  Basically, I'd like to be able to
> have a single PHP application that remembers its state as users click on
> links.  When the user clicks on a link, though, the user unavoidably
> re-requests the URL from the web server, which forces the PHP application to
> reload.  I'm therefore uncertain as to how I should keep the program in a
> state in which it remembers things like login information when the users
> have to click on links in order to navigate the application.
>
> This is especially an issue for me when it comes to maintaining things like
> persistent connections to SQL servers.
>
> Thanks!
>
> James


Well php itself is stateless, aka "share nothing."  On each request
everything is always going to be built from the ground up unless you
really step in the way with other technologies such as an opcode cache
and memcached.

You can use the session extension to remember state between requests.
When someone posts a login form and it is correct, just throw the user
id into the session.  Then always check for a valid user id variable
in the session when you need authorization.

http://php.net/manual/en/session.examples.php

As for your database concern, most (if not all) of the db extensions
offer some sort of persistent connection pooling capability.  For
example ext/mysql offers mysql_pconnect.  With PDO you can do this:

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
    PDO::ATTR_PERSISTENT => true
));

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux