0

I have a problem with a certain PHP script running three times almost concurrently. It's only expected to run once, and I'm still investigating the cause of this issue.

In the meantime, I'd like to add a fix to the script itself that prevents it running multiple times. It already has existing functionality to set a database flag when it starts. Once that flag is set, further instances of that script running should detect the flag and abort execution. However, I believe that the scripts run too closely together in time for the first instance to set the flag before the second instance checks the flag. The sleep function doesn't solve the issue as the almost-concurrent scripts sleep at the almost-same time as one another.

Here's pseudocode of an excerpt of the script:

Check if flag is set
If it is, abort operation
If it isn't, proceed
  Set flag
  Execute API call
  etc...

Does anyone know of a potential solution to my problem?

Thank you!

0 Answers0