Reply to Re: [PHP] warning & question about mysql sessions & concurrency

Your name:

Reply:


Posted by Josh Whiting on 03/09/05 04:21

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация