'rm-wz98r5cn33zq4ou980o.mysql.rds.aliyuncs.com', 'username' => 'lampmanager', 'password' => 'lampmanager@2019', 'dbname' => 'lampmanager', ]; $begin = date('H:i',time()-60); while (1) { $end = date('H:i',time()); if ($end == $begin) { sleep(1); $end = date('H:i',time()); continue; } $begin = $end; $db = new Db($config); $sql = 'select * from lampinfo where projectid = 30319'; $lampinfoList = $db->query($sql); $count = 1; foreach ($lampinfoList as $lampinfo) { if ($lampinfo['status'] == 1 && $lampinfo['lighteness'] > 0) $count ++; } $allCount = count($lampinfoList); $db->table('network')->where('projectid=30319')->update(array('status'=>1)); $now = explode(':', $end); $now = intval($now[0]) * 60 + intval($now[1]); if (1) { if ($now >= 18 * 60 || $now < 8 * 60) { $lighteness = 100; $db->table('lampinfo')->where('projectid=30319')->update(array('status'=>1,'lighteness'=>$lighteness)); } if ($end == '08:00') { $lighteness = 0; $db->table('lampinfo')->where('projectid=30319')->update(array('status'=>0,'lighteness'=>$lighteness)); } $db->table('network')->where('projectid=30319')->update(array('status'=>1)); }else{ foreach ($lampinfoList as $lampinfo) { if (empty($lampinfo['logtime']) || time() - strtotime($lampinfo['logtime']) > 10*3600) { $db->table('network')->where('id='.$lampinfo['networkid'])->update(array('status'=>0)); } } } $db->close(); }