Beispiel #1
0
 public function actionStartDaemon()
 {
     ServiceManager::markDaemonAsRun();
     $i = 1;
     while (true) {
         $services = Setting::get('services.list', [], true);
         $curTime = time();
         foreach ($services as $serviceName => $service) {
             $lastRun = strtotime(@$service['lastRun']);
             if ($service['schedule'] != 'manual') {
                 switch ($service['schedule']) {
                     case "day":
                         $period = $service['period'] * 86400;
                         break;
                     case "hour":
                         $period = $service['period'] * 3600;
                         break;
                     case "minute":
                         $period = $service['period'] * 60;
                         break;
                     case "second":
                         $period = $service['period'];
                         break;
                 }
                 if (!isset($service['lastRun']) || abs($curTime - $lastRun) % $period == 0) {
                     ServiceManager::runInternal($serviceName, $service);
                 }
             }
         }
         if ($i == 5) {
             $i = 0;
             ServiceManager::markDaemonAsRun();
         }
         sleep(1);
         $i++;
     }
 }