getCrossCheckAccount(); print_r($list); echo "\n"; exit; //测试数据 $list[] = [ 'user' => 'mayi001', 'passwd' => 'Eg98*!f@42', 'ext_info' => 'crossref-26027,zzz', ]; if (empty($list)){ throw new Exception('获取crosscheck账号列表为空'); } foreach($list as $v){ // 获得crosscheck账号密码 $user = trim($v['user']); $passwd = $v['passwd']; $extdata = explode(',', $v['ext_info']); $tenant = $extdata[0]; // 账号cookie文件路径 $cookie_path = __DIR__ . '/../cookie_file/'.$user.'.txt'; $obj->cookie_path = $cookie_path ; if (file_exists($cookie_path)) { chown($cookie_path, 'nobody'); chgrp($cookie_path, 'nobody'); chmod($cookie_path, 0777); } $capture_path = __DIR__ . '/../cookie_file/screen_shots/'; if (!is_dir($capture_path)) { mkdir($capture_path, 0777, true); chown($capture_path, 'nobody'); chgrp($capture_path, 'nobody'); } // 检测账号cookie是否有效 $res = $obj->islogin(); if ($res) { // 账号cookie有效,无需登录 //exit('账号cookie有效,无需登录'.$user.PHP_EOL); $str_log = date('Y-m-d H:i:s')."|验证成功|".$user; file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); }else{ //exit('账号cookie过期,无需登录'.$user.PHP_EOL); // 账号cookie过期,需要重新登录 unlink($cookie_path); // 删除过期cookie // 执行java登录脚本,获取脚本运行的时间 $start_time = time(true); //$cmd = 'java -jar /datacenter/java/crossrefLogin.jar "' . $user.'" "'.$passwd.'" "'.$cookie_path.'"'; $cmd = "java -jar /datacenter/java/crossrefLogin_v2.jar -u '{$user}' -p '{$passwd}' -f '{$cookie_path}' -t '{$tenant}' -capture_path '{$capture_path}'"; echo $cmd.PHP_EOL; //java -jar crossref-1.0-SNAPSHOT.jar -u '2105444612@qq.com' -p '038300asz_A' -f './mayi2_cookie.txt' -capture $console_str = trim(shell_exec($cmd)); // 计算脚本运行时间 $end_time = time(true); $run_time = $end_time - $start_time; $run_time_str = date('i:s', $run_time); $str_log = date('Y-m-d H:i:s')."|登录信息|".$console_str."|运行时间:".$run_time_str; file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); // 判断登录是否成功 if (strpos($console_str, '登录成功') === false) { // 登录失败 // 记录日志 $str_log = date('Y-m-d H:i:s')."|登录失败|".$user."|运行时间:".$run_time_str; file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); }else{ // 登录成功 // 记录日志 $str_log = date('Y-m-d H:i:s')."|登录成功|".$user."|运行时间:".$run_time_str; file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); } system("pkill -9 chrome"); } } sleep(5); // 删除锁文件 unlink($lock_file); }catch(Exception $e){ $str_log = date('Y-m-d H:i:s')."|异常退出|异常信息:".$e->getMessage(); 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; }