Last active
August 29, 2015 14:21
-
-
Save CosmoCleaner/5ebd87b059039039e05d to your computer and use it in GitHub Desktop.
phpの重複実行を避けるスクリプト
This file contains 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 | |
if(count($argv) < 1){ | |
echo "no argument."; | |
return; | |
} | |
$script_name = $argv[1]; | |
// check script existance | |
if(!file_exists("./{$script_name}")){ | |
echo "no script."; | |
return; | |
} | |
// check lockfile | |
$lockfile = "./{$script_name}.lock"; | |
if(file_exists($lockfile)){ | |
echo "{$script_name} is already executing now."; | |
return; | |
} | |
// execute | |
touch($lockfile); | |
require("./{$script_name}"); | |
unlink($lockfile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment