Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will a php script wait if it wants to read from a locked table?

I have a cli php script that is executed whenever an email arrives at a specific address.

When a new email arrives a new instance of the script is executed but because they read/write to the same DB tables sometimes wrong data is written.

My question is if the first script puts a lock on all the tables that it needs and a second/third etc instance of the script is run, will they wait for the tables to be unlocked by the first executed script? If so for how long?

In the end what I'm trying to do is make the scripts do their read/writes one after the other in a serial fashion so as to avoid duplication and errors.

like image 320
jimmy Avatar asked Oct 22 '22 08:10

jimmy


1 Answers

Yes, it will wait. This is done by the database server, the client application is totally unaware that it's happening -- as far as it can tell, the database is just being slow to perform the query.

like image 138
Barmar Avatar answered Oct 24 '22 10:10

Barmar