Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sam9's avatar
Level 50

Using Laravel lockForUpdate() while updating Users funds

Am using Laravel v5.2, Eloquent, MySql innodb.

I Have to update any user's available funds. So its seems logical to lock it while updating so it don't get updated from any other source and saving it with incorrect fund balance.

But my question is, if 2 or more queries came together to update the same user's funds and the 1st query locks it for select/update what will happen to the 2nd query?

  1. Will the 2nd query attempt generate some error?
  2. what will happen to the 2nd query while the row is locked?
  3. Will the MySql let the 2nd query wait for the lock to be removed and automatically executes that or some mysql error is thrown?
  4. Do i have to do something in php to handle the 2nd or further queries?
0 likes
3 replies
sam9's avatar
Level 50

no replies... :| am really waiting for some insight...

2 likes
Blues's avatar

Anyone? It would be nice to learn more about it.

1 like

Please or to participate in this conversation.