多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
以下为演示代码,请根据实际情况修改代码 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 )); } } }