Skip to content

Instantly share code, notes, and snippets.

@CosmoCleaner
Last active August 29, 2015 14:21
Show Gist options
  • Save CosmoCleaner/5ebd87b059039039e05d to your computer and use it in GitHub Desktop.
Save CosmoCleaner/5ebd87b059039039e05d to your computer and use it in GitHub Desktop.
phpの重複実行を避けるスクリプト
<?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