javascript - PHP: Best way forward [serialisation, objects, Redis] -


i have been developing php application quite while. (basic) idea follows; users can build web-pages using blocks. these blocks can contain images, text etc. each of these blocks have own options. these blocks defined in domain driven design through php.

i've build application use php-based controller handles requests jquery/javascript front. each time user edits option send controller unserialises collection of blocks (php-objects) redis and/or php-session , sets the attributes of blocks edited or adds/removes 1 of blocks. enforce domain logic.

which fine developing myself. never kept race conditions , such in mind. while moving forward product notice people lose data. i'll explain happens;

  1. user edits option of block
  2. press save
  3. a request made controller which,
  4. unserialises collection and
  5. sets blocks based on uuid
  6. puts blocks in collection and
  7. serialises collection again.

there scenario's 2 concurrent request might created override edits of 1 of both requests.

i know need rewrite part of application. question best approach. could;

  1. implement javascript library take me lot of work because require me rewrite entire part of application. not have lot of experience implementing javascript based solutions. not might stepping new. want javascript testing prevent future problems occurring , enable cross-browser testing
  2. apply redis / session locking enable controller process single request , prevent concurrent requests overwriting data set in previous request. lower chance of concurrent request , data loss, not fully. people real slow internet connection might connections losing when might produce lot of concurrent requests.

i'm curious other approaches might missing, or if 1 of 2 mentioned above suffice.

as far understand problem, may want implement optimistic locking.

a simple way implement it, version aggregate.

every time edits object, increment version.

when post edited blocks, send version on trying apply changes.

then, when getting object persistence storage, compare version , ensure working on up-to-date object.

if is, save it, if not, reject modification, notify user, , reload object, , take appropriate action (it depends on needs).


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -