Last active
September 9, 2015 16:30
-
-
Save codegenin/c8966d84de6ff4736aee to your computer and use it in GitHub Desktop.
Revisions
-
codegenin renamed this gist
Sep 9, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
codegenin created this gist
Sep 9, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ <?php $filename = "myscript.lock"; $lifelimit = 120; // in Second lifetime to prevent errors /* check lifetime of file if exist */ if(file_exists($filename)){ $lifetime = time() - filemtime($filename); }else{ $lifetime = 0; } /* check if file exist or if file is too old */ if(!file_exists($filename) || $lifetime > $lifelimit){ if($lifetime > $lifelimit){ unlink($filename); //Suppress if exist and too old } $file=fopen($filename, "w+"); // Create lockfile if($file == false){ die("file didn't create, check permissions"); } /* Your process */ unlink($filename); //Suppress lock file after your process }else{ exit(); // Process already in progress }