concurrency, locks, multi-user app.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm investigating this subject, particularly DB interactions, and could
use input.
It seems the dominant consensus, in these discussions is "use  flock()
I guess this would be similar to, in Java terms, using  synchronized
(objLock) { ... }

This lends itself to OOP modularization, localization of reads and
writes, using locks.

Also, MySQL might say in the manual,
this storage engine locks at the [page | row | ...] level.

But what does this get you ?
If the goal is consistent data, and no simultaneous writes, its a
worthy goal.
But how should the application be designed ?
Do you limit access to reports, displays, forms on data that is
currently being written ?
If a PHP flock() or DB lock impedes access, what then ?
Does it wait a time slice then try ? or throw error ?  fatal error ?
recover ?

Any good articles, references ?  any from Wrox, O'Reilly ?   TIA for

Re: concurrency, locks, multi-user app.

awebguynow wrote:

Quoted text here. Click to load it


Problem with flock is however that W$-machines have no clue what you are  
talking about. :-(

Quoted text here. Click to load it


It means that mySQL will manage this for you where and when appropriate.
You do not have to worry about the details yourself, unless you want to  
optimize (you can give mySQL hints), or want to lock some tables/rows for  
some other reason.

In general: Just trust your database engine to do its job right.

Quoted text here. Click to load it

How can we answer such a question?

Some shots in the dark:  

If you are doing webstuff: Just include a connection-file above every script  
that gives you a valid connection to the datatabase.
Use this connection in your script for select/update/delete/etc.

I am unsure if mySQL understands transactions.
If you want a better database, switch to Postgresql: it is a lot more  

Quoted text here. Click to load it

Most database engines have a maximum number of connections, if that is what  
you mean. Ofter 32 or 64. But that number can easily be modified by some  

Quoted text here. Click to load it

flock and database row/table lock are two different things. They share the  
word 'lock' but that is about it.
But for both goes that the script that trying it waits and tries again.
Maybe they use some fancy sheduling behing the scenes (like monitor  
functionality found in Java), but I am unsure about the how and when.

Quoted text here. Click to load it

For flock: just try it yourself.
Make 1 script that flocks a file.
Make another that tries this too.

Quoted text here. Click to load it is a good resource. Be sure to read all usercontributions too.  
They help a lot understanding what is going on.

Hope this helped you a bit.

Erwin Moller

Site Timeline