PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 11, 2022

[FIXED] MySQL Timer for locked row

 February 11, 2022     cron, lamp, mysql, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing