Coding Tactic: Flock Scripts!
Scripts are pieces of code that are typically scheduled to repeat at some interval. Like, once a day archive any log files that are bigger than 100MB. Or, check for new emails every 5 minutes.
An easy problem to run into is that your script might not finish before it’s meant to run again. Without going into a ton of detail, this can lead to scripts piling up and crash your server in production.
I know. I’ve crashed a production server using this exact technique mistake!
The solution: flock. When the script tries to run it can check a file lock (flock) to see if any other scripts are blocking it. If so, it skips its run and the server lives happily ever after.