PHP通过lock控制进程只执行一次

$lock_file = dirname(__FILE__) . "/process.lock";
$lock_file_handle = fopen($lock_file, 'w');

if ($lock_file_handle === false){
die("can not create lock file {$lock_file}\n");

}
if (!flock($lock_file_handle, LOCK_EX + LOCK_NB)){
die(date("Y-m-d H:i:s"). " Process already exists.\n");
}

posted @ 2017-02-28 08:44  洋葱土豆随心匠  阅读(562)  评论(0编辑  收藏  举报