Good transaction security code in the php world is not the norm, but there are many examples if you look at java or .net code examples.
The best database code I've seen puts queries into a function and retries about 3 times before giving up and registering / queuing up. Hope this takes care of your problem.
Best practice would be to use innodb tables and put all your critical sql statements in a transaction that is either committed or canceled. Thus, your data is in a consistent state, even if one particular request fails. (note that this can also complicate locking issues if you are not careful).
You do not want to sleep long with the survey, as this may hang your users browser. They need an immediate response to confirm that the purchase has passed. Putting a job in a queue with a cron job or server daemon is another way, but it does not give the user immediate feedback and is probably unnecessary for this purpose.
If immediate attempts do not work, you have another problem with basic blocking, the reason for the failure is that you need to train.
source share