> I am currently storing an object in a MySQL database. The object is
> continually being updated by many (possibly simultaneous) requests. Workflow
> looks something like this:
> 
> 1. Data comes in from one of many sources
> 
> 2. PHP reads the object from the database
> 
> 3. PHP adds data to the object
> 
> 4. PHP writes the object back to the database
> 
> I think I'm running into a concurrency issue where I have record of new data
> being received, but the database object does not reflect the new data. I
> feel like I need to make the object a mutex but I have no idea how to go
> about doing that with PHP. Can anyone provide alternative designs that will
> be a little more robust and handle concurrency?

This is actually a concurrency issue that spans the database and php. You will
need to create some type of locking that will allow a request to lock the db for
read/write as it completes it "unit of work" and in your php code. Most
languages suffer from this type of scenario. This also introduces some
performance issues as well. For example, if you lock on the db level then you
will have requests that block as the workflow tries to complete for each 
request.

As you are using mysql, then I would suggest that you use the locking in mysql
and propagate that information up to our php objects. Here is a pretty easy
example of what I am talking about:

http://www.perplexedlabs.com/2008/02/06/mutex-with-php-and-mysql/


-- 
thebigdog

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to