3 Replies Latest reply on Oct 29, 2009 1:32 AM by kevnug

    How to maintain data consistency for multi-user Flex app?

    kevnug

      hello all,

       

      All of the Flex/AIR apps I've built so far have basically been CMS backend apps for websites intended for single concurrent user access only.

       

      Now I'm working on a project that requires multi-concurrent-user access and I'm contemplating the best way to maintain data consistency across instances of the running app.

       

      I use the PHP Zend framework server-side with relatively basic PHP classes performing the CRUD operations and returning typed objects or arrays of objects as required.  So my Flex apps get arrays of complete datasets when the user launches & logs in successfully. 

       

      Then when the user for instance adds, updates or deletes a record, that object (eg. BookVO) is passed to the server, the class/method is executed and on success returns the same object back to the client.

       

      The client then modifies the relevant local ArrayCollection by using the addItem, setItemAt or removeItemAt methods.

       

      Obviously this means that as soon as someone updates a record, the other users will have inaccurate data on their instances of the app.

       

      My thoughts so far: 

      1) make the PHP classes smarter - send the old version of the object as well as the new, do a compare to make sure the database record matches the old object, if it does the record has not changed and can be updated, otherwise give the user the option of retrieving the latest record or replacing the record on the database.

       

      2) add a timestamp column to every table - again do a compare and give the user the option of updating the app with the latest data or replacing the database record

       

      3) somehow ping the connected clients when records change and cause them to refresh either that record or that dataset

       

      My thoughts are possibly rudimentary at best - so I'd really appreciate your feedback!

       

      The other thing is I'd really prefer the solution to be PHP/MySQL and not using BlazeDS/LCDS because of hosting arrangements.

       

       

      Thanks for your help!

       

       

      Cheers,

       

      Kevin.

        • 1. Re: How to maintain data consistency for multi-user Flex app?
          msakrejda Level 4

          (2) seems to be a pretty standard approach for these sorts of things, unless you can spend the time to do (3). For (3), you can use a Comet-like approach (something like Granite DS Gravity--not sure if existing solutions exist for PHP, but it's not rocket surgery to roll your own) or polling / long-polling (which will be simpler if not quite as accurate).

          1 person found this helpful
          • 2. Re: How to maintain data consistency for multi-user Flex app?
            kevnug Level 1

            Thanks for the pointer.  I'm a bit worried about the users having to decide whether to dump the changes they've just made to a record or to overwrite someone else's changes.

             

            I've since taken another look at Weborb for PHP - something I investigated briefly a while back but abandoned because of lack of good documentation unless you take a support plan and Adobe's team-up with Zend

             

            Using the Weborb Data Management for Flex (WDMF) I was able to migrate my basic CRUD services across in literally 5 mins and as Weborb supports Flex Messaging and runs on PHP, I'm nearly there.

             

            Now if I can just find some info on implementing PHP session management in Weborb to migrate the authentication class...

             

            Anyone had any experience with this?

            • 3. Re: How to maintain data consistency for multi-user Flex app?
              kevnug Level 1

              For anyone else that comes looking for an answer..

               

              1. I moved over to using Weborb for PHP v3.6 for remoting
              2. converted my remoting classes with little effort
              3. couldn't get Weborb's security adaptor authenticating against mysql so implemented a PHP session based auth controller
              4. I then used Weborb's messaging service to send updates out to connected clients when records are created, updated or deleted

               

              I found the lack of documentation for Weborb for PHP very frustrating.  I used some of the Weborb.NET docs for reference but as you'd expect there are differences.

               

              The last lingering annoyances are:

              1. There seems to be a 'size limit' for message body contents either on the AS3 side or Weborb - I tried sending typed objects in the AsyncMessage body to do single record updates in the app but when the message was received I got an error saying "Adobe AIR Error - end of file" or something like that and the message queue stopped working until I cleared the server message cache.  So instead I send a string of which dataset needs updating - less efficient but serves the purpose for the moment.
              2. I can't for the life of me find any info on clearing the PollCache folder which is where messages are stored on the server even after delivered! I read about some people running server side scripts to clear the cache every now and then... but can't believe you can't delete them from via a command from the client or set a TTL.  I found some reference to setting the <message-time-to-live>  property in the  messaging-config.xml but it seems to have not effect.

               

              Anyway, that's my take on "How to maintain data consistency for multi-user Flex app?".