Browse Source

调整失败次数

master
李昭辉 1 month ago
parent
commit
f602b81cd1
  1. 39
      crontab/crosscheck_auto_shell.php

39
crontab/crosscheck_auto_shell.php

@ -1,14 +1,12 @@
<?php
include(__DIR__ . '/../lib/mCrossCheck.php');
ini_set('date.timezone', 'Asia/Shanghai');
// 同一时间只能有一个进程在运行
$lock_file = __DIR__ . '/crosscheck_auto_shell.lock';
if (file_exists($lock_file)) {
echo '另一个进程正在运行,请稍后重试。' . PHP_EOL;
exit(1);
// 避免程序重复运行
$need_run = cProcessNum();
if(!$need_run) {
exit("is running, exit.\n");
}
// 创建锁文件
touch($lock_file);
$log_file = __DIR__ . '/../logs/'.date('Y-m-d').'/crosscheck_auto_shell.log';
$log_dir = dirname($log_file);
@ -21,7 +19,9 @@ try{
$list = $obj->getCrossCheckAccount();
print_r($list);
echo "\n";
exit;
//测试数据
$list[] = [
'user' => 'mayi001',
@ -105,4 +105,25 @@ try{
file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND);
// 删除锁文件
unlink($lock_file);
}
}
/**
* 进程上限限制
*
* @return boolean
*/
function cProcessNum() {
// 当前程序文件名包含路径
$path_deal = __FILE__;
$processnum = 1;
$cmd = "ps -ef | grep '{$path_deal}' | grep -v grep | grep -v '\/bin\/sh' | grep -v 'sh -c' | wc -l";
$rcmd = @popen($cmd, 'r');
$num = @fread($rcmd, 512);
$num += 0;
echo "[$path_deal]进程数超过{$processnum}个,当前进程数{$num}个\n";
@pclose($rcmd);
if($num >$processnum) {
return false;
}
return true;
}
Loading…
Cancel
Save