Esempio n. 1
0
 /**
  * ZZZzzz......
  * Sleep state to the database to provide session persistance
  * We need a few seconds to run this :-(
  *
  * @param bool $alreadyComplete
  */
 public function saveState($alreadyComplete = FALSE, $line = 0)
 {
     // bfLog::log('Sleeping audit status to persistent db store');
     // When did we complete this step/audit
     $this->endTime = time();
     // make sure we cache the connectorversion
     $this->connectorversion = file_get_contents('./VERSION');
     // Inject the state to the database
     $obj = new stdClass();
     foreach ($this as $k => $v) {
         // Dont save private/system objects
         if ($k == 'db' || $k == '_steps' || $k == '_timer' || substr($k, 0, 1) == '_') {
             continue;
         }
         // convert objects and arrays to strings
         if (is_object($v) || is_array($v)) {
             $v = json_encode($v);
         }
         // inject to the object we will return
         $obj->{$k} = $v;
     }
     // Save state
     file_put_contents('tmp/STATE.php', '<?php die();?>' . serialize($obj));
     // save the step we are on
     $obj->step = (string) $this->_steps;
     // report back to service with json object;
     $obj->maxPHPMemoryUsed = round(memory_get_peak_usage(TRUE) / 1048576, 2);
     $obj->queuecount = $this->_getQueueCount('files');
     // legacy
     $obj->filestoscan = $obj->queuecount;
     $obj->logtail = bfLog::getTail();
     //bfLog::log(json_encode($obj));
     // close db
     unset($this->db);
     unset($this->_timer);
     unset($this->_steps);
     // go to sleep, but first tell the service we are dreaming...
     bfEncrypt::reply(bfReply::SUCCESS, $obj);
 }