I have a script that receives free market requests when there is an update to an order.
When a request is made, the free market sends 5 to 10 requests for this script at the same time (do not ask me why it sends so many requests at the same time, since all are the same), and I enter in my bank just one of them.
The problem is basically in the lines below, which check if the order has already been entered in the bank table. ($ obj_sql is a simple mysql handler, and I think the problem is not in it.)
$jatemped = $obj_sql->Get("select count(ped_id) from pedidos where mel_order='$id_order'");
if ($jatemped===0) {
$obj_sql->Query("insert into pedidos (mel_order) values ('".$id_order."')");
}
The mel_order field is not unique, as it may contain records in the requests table with this blank field.
The problem is that sometimes the insert is duplicated by a second script request, with the same $ id_order in the mel_order field.
Is there some kind of cache between the insert and the select of the next execution of the script that it can not see the insert that has just been made?
How can I resolve this?