Created
May 6, 2025 16:28
-
-
Save vielhuber/04ecb8ef50518dff60d482e76e3d6c84 to your computer and use it in GitHub Desktop.
lock files prevent multiple duplicate script execution #php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $lock = fopen(sys_get_temp_dir() . '/' . md5(__FILE__) . '.lock', 'c'); | |
| if (!flock($lock, LOCK_EX | LOCK_NB)) { | |
| echo 'current script already running...'; | |
| die(); | |
| } | |
| echo 'script running...'; | |
| sleep(10); | |
| // this is not needed, because the lock is released on script end (also on error) | |
| //fclose($lock); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment