/** * * @param nc_search_indexer $indexer * @param $cycle_number * @return boolean TRUE: остановка для перезапуска, FALSE: продолжение выполнения */ protected function interrupt_if_needed(nc_search_indexer $indexer, $cycle_number) { $memory_use = function_exists('memory_get_usage') ? memory_get_usage() : 0; $time_use = time() + $this->delay - $this->start_time; $out_of_memory = $out_of_time = false; // проверяем память if ($this->memory_threshold > 0) { if ($this->memory_threshold <= 1) { // относительные значения $out_of_memory = $memory_use / $this->memory_limit >= $this->memory_threshold; } else { // абсолютные значения $out_of_memory = $memory_use >= $this->memory_threshold; } } // проверяем время if ($this->time_threshold > 0) { if ($this->time_threshold <= 1) { // относительные значения // 'max_execution_time' ($this->time_limit) может быть равен 0 при запуске из консоли $out_of_time = $this->time_limit && $time_use / $this->time_limit >= $this->time_threshold; } else { // абсолютные значения $out_of_time = $time_use >= $this->time_threshold; } } // проверяем ограничение на количество циклов $is_last_cycle = $this->cycle_limit > 0 && $cycle_number > $this->cycle_limit; // останавливаемся, когда достигли лимита if ($out_of_memory || $out_of_time || $is_last_cycle) { $indexer->interrupt("mem: {$memory_use} bytes; time: {$time_use} s"); return true; } return false; }