$fp = fopen(sys_get_temp_dir().DIRECTORY_SEPARATOR."lock.txt", "w+"); if (flock($fp, LOCK_EX | LOCK_NB)) { // do an exclusive lock // YOUR CODE GOES HERE flock($fp, LOCK_UN); // release the lock } else { echo "Couldn't get the lock!"; } fclose($fp);
Quelle: https://stackoverflow.com/questions/5428631/php-preventing-collision-in-cron-file-lock-safe