Beispiel #1
0
 public static function cleanCache($force = false)
 {
     $cacheFiles = glob(CACHE_PATH . DS . '*', GLOB_NOSORT);
     // $cacheFiles += glob(TMP_PUBLIC_PATH . DS . '*', GLOB_NOSORT);
     $minToKeep = !$force ? time() - 12 * 3600 : time();
     foreach ($cacheFiles as $cacheFile) {
         $age = File::modified($cacheFile);
         if ($age < $minToKeep) {
             $tabFile = explode(DS, $cacheFile);
             ThinLog(Arrays::last($tabFile) . ' => ' . date('d/m/Y H:i:s', $age), null, 'suppression cache');
             File::delete($cacheFile);
         }
     }
 }
Beispiel #2
0
 /**
  * Get time of execution from all queue entries
  *
  * @param int $format Format of the returned data
  * @return int|float
  */
 public static function get($format = self::SECONDS)
 {
     // stop timer if it is still running
     if (static::$_running === true) {
         ThinLog('Forcing timer to stop', E_USER_NOTICE);
         static::stop();
     }
     // reset all values
     $sec = 0;
     $usec = 0;
     // loop through each time entry
     foreach (static::$_queue as $time) {
         // start and end times
         $start = $time[static::CMD_START];
         $end = $time[static::CMD_STOP];
         // calculate difference between start and end seconds
         $sec_diff = $end['sec'] - $start['sec'];
         // if starting and finishing seconds are the same
         if ($sec_diff === 0) {
             // only add the microseconds difference
             $usec += $end['usec'] - $start['usec'];
         } else {
             // add the difference in seconds (compensate for microseconds)
             $sec += $sec_diff - 1;
             // add the difference time between start and end microseconds
             $usec += static::USECDIV - $start['usec'] + $end['usec'];
         }
     }
     if ($usec > static::USECDIV) {
         // move the full second microseconds to the seconds' part
         $sec += (int) floor($usec / static::USECDIV);
         // keep only the microseconds that are over the static::USECDIV
         $usec = $usec % static::USECDIV;
     }
     switch ($format) {
         case static::MICROSECONDS:
             return $sec * static::USECDIV + $usec;
         case static::MILLISECONDS:
             return $sec * 1000 + (int) round($usec / 1000, 0);
         case static::SECONDS:
         default:
             return (double) $sec + (double) ($usec / static::USECDIV);
     }
 }