$PHP_SELF = realpath($_SERVER['PHP_SELF']);
if (!($argc > 1)) {
    $lock_file = $PHP_SELF . '.lock';
} else {
    unset($argv[0]);
    $lock_file = $PHP_SELF . '.' . implode('.', $argv) . '.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");
}

此外,为防止出现定时脚本的死循环使服务器挂掉,要避免使用ini_set('memory_limit', -1)

想知道执行的程序需要多大内存可以使用函数memory_get_peak_usage()



相关文章:

  • 2022-01-03
  • 2021-07-24
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-12-26
  • 2021-10-17
  • 2022-12-23
猜你喜欢
  • 2022-01-04
  • 2021-10-04
  • 2021-11-18
  • 2018-04-02
  • 2021-06-08
  • 2022-12-23
  • 2021-09-20
相关资源
相似解决方案