Re: warning & question about mysql sessions & concurrency

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

 



On Tue, Mar 08, 2005 at 10:38:28AM -0800, Richard Lynch wrote:
> Josh Whiting wrote:
> > SO, does anyone have some code that uses MySQL to replace PHP's native
> > session storage that also correctly handles this concurrency problem?
> 
> Create your MySQL session tables using ENGINE=innoDB (in older MySQL, use
> TYPE=innoDB)
> http://mysql.com can tell you lots more about innoDB
> 
> Then just wrap the contents of each function from the books in a BEGIN
> query to make them be transactions...  Err, no, I mean, start the
> transaction in the one function and COMMIT in the save function.
> 
> That should take care of all the concurrency issues, I think.

Agreed, initially I thought of that but I also need to use transactions
in my business logic and MySQL doesn't support nested transactions, so
I'd have to open a separate connection to the DB to handle the session
transaction while another connection handles the business
transaction(s).  I'm hoping to find a solution that uses locking in the
application level instead of the database.  Were I using a DB that
supported nested transactions, it would be a different story.  maybe 
it's time to switch databases.

> I guess I'm just saying that in the real world, the race condition for a
> single user/session just doesn't occur that often, and when it does, the
> user generally recognizes the problem/error and accepts that they caused
> it by being impatient or running two windows at once or whatever they did
> that made it happen.
> 
> That doesn't make it Right, but it does make it Practical.

Point taken.  I guess it's almost more of a pyschological thing for me 
as a programmer - the idea of writing code vulnerable to race conditions 
just doesn't sit well with me.

on the other hand, with the growing popularity of tabbed browsers, and 
of coures the frames issue, i think it is reasonable to demand proper 
behavior during concurrent requests, and while you may not be using 
frames, lots of sites do, and that's a setup for a real headache.

thanks
/josh

-- 
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