Issue
I am not very experienced with advanced MySQL but I was wondering what is the best way to implement a time out. I have an iPhone app that 'locks' a row in a table while it is creating the content to be written back to it. It's just a BOOL column that I toggle back and forth. The problem is, if my app crashes or they lose network connection while it is locked, it will not unlock. I would like to set a 5 minute timer or something on the server to unlock the row if they fail to complete the process within that time. My web api is written in PHP.
Can I do this with MySQL? Do I need to create a cron job?
Solution
You could create a server-side application (cron job could work) that periodically looks at rows with a lock and unlocks them if they've expired. To know whether they have expired, you need to include a datetime column which is set to the current time when the lock is applied.
Alternatively, you can skip the server-side app and just let your iPhone app check the datetime, and reset the lock if it's been long enough.
In either case, the key is to add a datetime column and utilize that to know the age of the lock.
Answered By - JYelton
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.