💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
以下为演示代码,请根据实际情况修改代码 function checkPhpScript($cronFiles){ @exec ( "ps aux|grep .php", $scripts ); if($cronFiles && $scripts){ checkRepeatScript($scripts); foreach ($cronFiles as $key => $value) { foreach ($scripts as $k => $v) { if(strstr($v,$value)){ unset($cronFiles[$key]); } } } if(is_array($cronFiles) && count($cronFiles)>0){ return $cronFiles; } } return false; } function checkRepeatScript($scripts){ $checkScripts = array(); $repeatScripts = array(); foreach ($scripts as $k => $v) { if(strstr($v,'cron.php')){ continue; } else{ $b = strstr($v,'/usr/local/php5.5/bin/php'); if($b){ $key = md5($b); if(isset($checkScripts[$key])){ $repeatScripts[] = $v; } else{ $checkScripts[$key] = 1; } } } } if(count($repeatScripts)>0){ $insertAlert = true; $aObj = new \model\alert; $alert = $aObj->find(array( 'condition'=>array('status'=>array('$exists'=>true)), 'field'=>array(), 'sort'=>array('created'=>-1), )); if(isset($alert[0])){ if(time()-$alert[0]['created']->sec<600){//如果10分钟内刚报过警,就不查了 $insertAlert = false; } } if($insertAlert){ $ip = localIPCore(); $aObj->create(array( 'description'=>'服务器:'. $ip .' 有重复进程', 'debug'=>$repeatScripts, 'created'=>new \MongoDate(), 'status'=>0 )); } } }