的PHP / MySQL / jQuery的记录的悲观锁定 [英] PHP/MySQL/jQuery Pessimistic Locking of Record

查看:117
本文介绍了的PHP / MySQL / jQuery的记录的悲观锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想开发一些简单的记录锁定为我参与的应用程序。有一些用户谁需要几个小时的时间才能完成创纪录的编辑。这会导致问题时,其他人想要做出改变的记录。目前没有锁定参与。

I've been thinking about developing some simple record locking for an application I'm involved in. There are a few users who will take literally hours to complete an edit of a record. This causes issues when someone else wants to make a change to the record. Currently there is no locking involved.

我不能肯定,乐观锁是可靠的在我的情况下,作为记录保存通AJAX请求。我期待在运用某种悲观锁定的;使用两个字段,例如, locking_user_id locking_timestamp ,我可以追踪谁的纪录开,最后一次被打开了。

I'm not certain that Optimistic locking is reliable in my case, as the record is saved thru an AJAX request. I'm looking at applying some kind of Pessimistic Locking; using two fields, such as, locking_user_id and locking_timestamp, I can track who has the record open and the last time it was opened.

不过,因为用户可能会打开它在一个小时的时间里,我怎么能知道,如果用户抛弃它,或者只是努力工作就可以了?我不想强迫他们更新它每隔5分钟〜然而,这可能是一种可能性(AJAX节约每5分钟)。

But, since the user may have it open for hours at a time, how can I know if the user abandoned it or is just working hard on it? I don't want to force them to update it every 5 minutes ~ yet that might be a possibility (AJAX save every 5 min).

也许jQuery的过程可以在用户的​​工作,并会火了一个AJAX请求(的getJSON)每5分钟更新locking_timestamp计数。这样我可以保持谁正在处理的记录。时间戳变老之后,我可以假设用户不再与reocrd工作。有没有人有经验,这种锁定?

Perhaps a jQuery process could be counting while the user works and would fire off an AJAX request (getJSON) every 5 minutes to update the locking_timestamp. That way I could maintain who is working on the record. After the timestamp gets "old", I can assume the user is no longer working with the reocrd. Has anyone had experience with this kind of locking?

推荐答案

更​​新与AJAX请求locking_timestamp是一个很好的战略,将迎刃而解。

Updating the locking_timestamp with AJAX requests is a fine strategy and will work out fine.

然而,在两个电话之间间隔5分钟似乎有点长了我。除非你有非常高的流量,像30秒是从用户的角度更好。想象一下,一个人必须等待5分钟,因为其他用户打开了记录,然后闭上了浏览器...

However, 5 minutes interval between the calls seem a little long to me. Unless you have really high traffic, something like 30 seconds would be better from a user's perspective. Imagine someone having to wait 5 minutes because another user opened the record and then closed his browser...

这篇关于的PHP / MySQL / jQuery的记录的悲观锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆