当前位置: 首页>>代码示例>>PHP>>正文


PHP Factory::getTimer方法代码示例

本文整理汇总了PHP中Akeeba\Engine\Factory::getTimer方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::getTimer方法的具体用法?PHP Factory::getTimer怎么用?PHP Factory::getTimer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Akeeba\Engine\Factory的用法示例。


在下文中一共展示了Factory::getTimer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postProcessDonePartFile

 /**
  * @param \Akeeba\Engine\Archiver\Base $archiver
  * @param \Akeeba\Engine\Configuration $configuration
  *
  * @return bool
  */
 protected function postProcessDonePartFile(\Akeeba\Engine\Archiver\Base $archiver, \Akeeba\Engine\Configuration $configuration)
 {
     $filename = array_shift($archiver->finishedPart);
     Factory::getLog()->log(LogLevel::INFO, 'Preparing to post process ' . basename($filename));
     $timer = Factory::getTimer();
     $startTime = $timer->getRunningTime();
     $post_proc = Factory::getPostprocEngine();
     $result = $post_proc->processPart($filename);
     $this->propagateFromObject($post_proc);
     if ($result === false) {
         Factory::getLog()->log(LogLevel::WARNING, 'Failed to process file ' . $filename);
         Factory::getLog()->log(LogLevel::WARNING, 'Error received from the post-processing engine:');
         Factory::getLog()->log(LogLevel::WARNING, implode("\n", array_merge($this->getWarnings(), $this->getErrors())));
         $this->setWarning('Failed to process file ' . basename($filename));
     } elseif ($result === true) {
         // Add this part's size to the volatile storage
         $volatileTotalSize = $configuration->get('volatile.engine.archiver.totalsize', 0);
         $volatileTotalSize += (int) @filesize($filename);
         $configuration->set('volatile.engine.archiver.totalsize', $volatileTotalSize);
         Factory::getLog()->log(LogLevel::INFO, 'Successfully processed file ' . basename($filename));
     } else {
         // More work required
         Factory::getLog()->log(LogLevel::INFO, 'More post-processing steps required for file ' . $filename);
         $configuration->set('volatile.postproc.filename', $filename);
         // Let's push back the file into the archiver stack
         array_unshift($archiver->finishedPart, $filename);
         // Do we need to break the step?
         $endTime = $timer->getRunningTime();
         $stepTime = $endTime - $startTime;
         $timeLeft = $timer->getTimeLeft();
         if ($timeLeft < $stepTime) {
             // We predict that running yet another step would cause a timeout
             $configuration->set('volatile.breakflag', true);
         } else {
             // We have enough time to run yet another step
             $configuration->set('volatile.breakflag', false);
         }
     }
     // Should we delete the file afterwards?
     if ($configuration->get('engine.postproc.common.delete_after', false) && $post_proc->allow_deletes && $result === true) {
         Factory::getLog()->log(LogLevel::DEBUG, 'Deleting already processed file ' . basename($filename));
         Platform::getInstance()->unlink($filename);
     } else {
         Factory::getLog()->log(LogLevel::DEBUG, 'Not removing processed file ' . $filename);
     }
     if ($post_proc->break_after && $result === true) {
         $configuration->set('volatile.breakflag', true);
         return true;
     }
     // This is required to let the backup continue even after a post-proc failure
     $this->resetErrors();
     $this->setState('running');
     return false;
 }
开发者ID:jvhost,项目名称:A-Website,代码行数:60,代码来源:Pack.php

示例2: pack_files

 /**
  * Try to add some files from the $file_list into the archive
  *
  * @return   boolean   True if there were files packed, false otherwise
  *                     (empty filelist or fatal error)
  */
 protected function pack_files()
 {
     // Get a reference to the archiver and the timer classes
     $archiver = Factory::getArchiverEngine();
     $timer = Factory::getTimer();
     $configuration = Factory::getConfiguration();
     // If post-processing after part creation is enabled, make sure we do post-process each part before moving on
     if ($configuration->get('engine.postproc.common.after_part', 0) && !empty($archiver->finishedPart)) {
         if ($this->postProcessDonePartFile($archiver, $configuration)) {
             return true;
         }
     }
     // If the archiver has work to do, make sure it finished up before continuing
     if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
         Factory::getLog()->log(LogLevel::DEBUG, "Continuing file packing from previous step");
         $result = $archiver->addFile('', '', '');
         $this->propagateFromObject($archiver);
         if ($this->getError()) {
             return false;
         }
         // If that was the last step for packing this file, mark a file done
         if (!$configuration->get('volatile.engine.archiver.processingfile', false)) {
             $this->progressMarkFileDone();
         }
     }
     // Did it finish, or does it have more work to do?
     if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
         // More work to do. Let's just tell our parent that we finished up successfully.
         return true;
     }
     // Normal file backup loop; we keep on processing the file list, packing files as we go.
     if (count($this->file_list) == 0) {
         // No files left to pack. Return true and let the engine loop
         $this->progressMarkFolderDone();
         return true;
     } else {
         Factory::getLog()->log(LogLevel::DEBUG, "Packing files");
         $packedSize = 0;
         $numberOfFiles = 0;
         list($usec, $sec) = explode(" ", microtime());
         $opStartTime = (double) $usec + (double) $sec;
         $largeFileThreshold = Factory::getConfiguration()->get('engine.scan.common.largefile', 10485760);
         while (count($this->file_list) > 0) {
             $file = @array_shift($this->file_list);
             $size = 0;
             if (file_exists($file)) {
                 $size = @filesize($file);
             }
             // Anticipatory file size algorithm
             if ($numberOfFiles > 0 && $size > $largeFileThreshold) {
                 if (!Factory::getConfiguration()->get('akeeba.tuning.nobreak.beforelargefile', 0)) {
                     // If the file is bigger than the big file threshold, break the step
                     // to avoid potential timeouts
                     $this->setBreakFlag();
                     Factory::getLog()->log(LogLevel::INFO, "Breaking step _before_ large file: " . $file . " - size: " . $size);
                     // Push the file back to the list.
                     array_unshift($this->file_list, $file);
                     // Return true and let the engine loop
                     return true;
                 }
             }
             // Proactive potential timeout detection
             // Rough estimation of packing speed in bytes per second
             list($usec, $sec) = explode(" ", microtime());
             $opEndTime = (double) $usec + (double) $sec;
             if ($opEndTime - $opStartTime == 0) {
                 $_packSpeed = 0;
             } else {
                 $_packSpeed = $packedSize / ($opEndTime - $opStartTime);
             }
             // Estimate required time to pack next file. If it's the first file of this operation,
             // do not impose any limitations.
             $_reqTime = $_packSpeed - 0.01 <= 0 ? 0 : $size / $_packSpeed;
             // Do we have enough time?
             if ($timer->getTimeLeft() < $_reqTime) {
                 if (!Factory::getConfiguration()->get('akeeba.tuning.nobreak.proactive', 0)) {
                     array_unshift($this->file_list, $file);
                     Factory::getLog()->log(LogLevel::INFO, "Proactive step break - file: " . $file . " - size: " . $size . " - req. time " . sprintf('%2.2f', $_reqTime));
                     $this->setBreakFlag();
                     return true;
                 }
             }
             $packedSize += $size;
             $numberOfFiles++;
             $ret = $archiver->addFile($file, $this->remove_path_prefix, $this->path_prefix);
             // If no more processing steps are required, mark a done file
             if (!$configuration->get('volatile.engine.archiver.processingfile', false)) {
                 $this->progressMarkFileDone();
             }
             // Error propagation
             $this->propagateFromObject($archiver);
             if ($this->getError()) {
                 return false;
             }
//.........这里部分代码省略.........
开发者ID:ForAEdesWeb,项目名称:AEW2,代码行数:101,代码来源:Pack.php

示例3: _run

 protected function _run()
 {
     $logTag = $this->getLogTag();
     Factory::getLog()->open($logTag);
     if (!static::$registeredErrorHandler) {
         static::$registeredErrorHandler = true;
         set_error_handler('\\Akeeba\\Engine\\Core\\akeebaBackupErrorHandler');
     }
     // Maybe we're already done or in an error state?
     if ($this->getError() || $this->getState() == 'postrun') {
         return;
     }
     // Set running state
     $this->setState('running');
     // Initialize operation counter
     $registry = Factory::getConfiguration();
     $registry->set('volatile.operation_counter', 0);
     // Advance step counter
     $stepCounter = $registry->get('volatile.step_counter', 0);
     $registry->set('volatile.step_counter', ++$stepCounter);
     // Log step start number
     Factory::getLog()->log(LogLevel::DEBUG, '====== Starting Step number ' . $stepCounter . ' ======');
     if (defined('AKEEBADEBUG')) {
         $root = Platform::getInstance()->get_site_root();
         Factory::getLog()->log(LogLevel::DEBUG, 'Site root: ' . $root);
     }
     $timer = Factory::getTimer();
     $finished = false;
     $error = false;
     $breakFlag = false;
     // BREAKFLAG is optionally passed by domains to force-break current operation
     // Apply an infinite time limit if required
     if ($registry->get('akeeba.tuning.settimelimit', 0)) {
         if (function_exists('set_time_limit')) {
             set_time_limit(0);
         }
     }
     // Loop until time's up, we're done or an error occurred, or BREAKFLAG is set
     $this->array_cache = null;
     while ($timer->getTimeLeft() > 0 && !$finished && !$error && !$breakFlag) {
         // Reset the break flag
         $registry->set('volatile.breakflag', false);
         // Do we have to switch domains? This only happens if there is no active
         // domain, or the current domain has finished
         $have_to_switch = false;
         $object = null;
         if ($this->class == '') {
             $have_to_switch = true;
         } else {
             $object = Factory::getDomainObject($this->class);
             if (!is_object($object)) {
                 $have_to_switch = true;
             } else {
                 if (!in_array('getState', get_class_methods($object))) {
                     $have_to_switch = true;
                 } elseif ($object->getState() == 'finished') {
                     $have_to_switch = true;
                 }
             }
         }
         // Switch domain if necessary
         if ($have_to_switch) {
             if (!Factory::getConfiguration()->get('akeeba.tuning.nobreak.domains', 0)) {
                 Factory::getLog()->log(LogLevel::DEBUG, "Kettenrad :: BREAKING STEP BEFORE SWITCHING DOMAIN");
                 $registry->set('volatile.breakflag', true);
             }
             // Free last domain
             $object = null;
             if (empty($this->domain_chain)) {
                 // Aw, we're done! No more domains to run.
                 $this->setState('postrun');
                 Factory::getLog()->log(LogLevel::DEBUG, "Kettenrad :: No more domains to process");
                 Factory::getLog()->log(LogLevel::DEBUG, '====== Finished Step number ' . $stepCounter . ' ======');
                 $this->array_cache = null;
                 //restore_error_handler();
                 return;
             }
             // Shift the next definition off the stack
             $this->array_cache = null;
             $new_definition = array_shift($this->domain_chain);
             if (array_key_exists('class', $new_definition)) {
                 $this->domain = $new_definition['domain'];
                 $this->class = $new_definition['class'];
                 // Get a working object
                 $object = Factory::getDomainObject($this->class);
                 $object->setup($this->_parametersArray);
             } else {
                 Factory::getLog()->log(LogLevel::WARNING, "Kettenrad :: No class defined trying to switch domains. The backup will crash.");
                 $this->domain = null;
                 $this->class = null;
             }
         } else {
             if (!is_object($object)) {
                 $object = Factory::getDomainObject($this->class);
             }
         }
         // Tick the object
         $result = $object->tick();
         // Propagate errors
         $this->propagateFromObject($object);
//.........这里部分代码省略.........
开发者ID:ForAEdesWeb,项目名称:AEW2,代码行数:101,代码来源:Kettenrad.php

示例4: apply_remote_quotas

 /**
  * Apply quotas for remotely stored files
  *
  * @return bool True on success
  */
 protected function apply_remote_quotas()
 {
     $this->setStep('Applying remote storage quotas');
     $this->setSubstep('');
     // Make sure we are enabled
     $config = Factory::getConfiguration();
     $enableRemote = $config->get('akeeba.quota.remote', 0);
     if (!$enableRemote) {
         return true;
     }
     // Get the list of files to kill
     if (empty($this->remote_files_killlist)) {
         Factory::getLog()->log(LogLevel::DEBUG, 'Applying remote file quotas');
         $this->remote_files_killlist = $this->get_remote_quotas();
         if (empty($this->remote_files_killlist)) {
             Factory::getLog()->log(LogLevel::DEBUG, 'No remote files to apply quotas to were found');
             return true;
         }
     }
     // Remove the files
     $timer = Factory::getTimer();
     while ($timer->getRunningTime() && count($this->remote_files_killlist)) {
         $filename = array_shift($this->remote_files_killlist);
         list($engineName, $path) = explode('://', $filename);
         $engine = Factory::getPostprocEngine($engineName);
         if (!$engine->can_delete) {
             continue;
         }
         Factory::getLog()->log(LogLevel::DEBUG, "Removing {$filename}");
         $result = $engine->delete($path);
         if (!$result) {
             Factory::getLog()->log(LogLevel::DEBUG, "Removal failed: " . $engine->getWarning());
         }
     }
     // Return false if we have more work to do or true if we're done
     if (count($this->remote_files_killlist)) {
         Factory::getLog()->log(LogLevel::DEBUG, "Remote file removal will continue in the next step");
         return false;
     } else {
         Factory::getLog()->log(LogLevel::DEBUG, "Remote file quotas applied successfully");
         return true;
     }
 }
开发者ID:ForAEdesWeb,项目名称:AEW2,代码行数:48,代码来源:Finalization.php

示例5: _addFile

 /**
  * The most basic file transaction: add a single entry (file or directory) to
  * the archive.
  *
  * @param bool   $isVirtual        If true, the next parameter contains file data instead of a file name
  * @param string $sourceNameOrData Absolute file name to read data from or the file data itself is $isVirtual is
  *                                 true
  * @param string $targetName       The (relative) file name under which to store the file in the archive
  *
  * @return boolean True on success, false otherwise
  *
  * @since  1.2.1
  */
 protected function _addFile($isVirtual, &$sourceNameOrData, $targetName)
 {
     static $configuration;
     static $memLimit = null;
     if (is_null($memLimit)) {
         $memLimit = ini_get("memory_limit");
         if (is_numeric($memLimit) && $memLimit < 0 || !is_numeric($memLimit)) {
             $memLimit = 0;
             // 1.2a3 -- Rare case with memory_limit < 0, e.g. -1Mb!
         }
         $memLimit = $this->_return_bytes($memLimit);
     }
     $isDir = false;
     $isSymlink = false;
     if (is_null($isVirtual)) {
         $isVirtual = false;
     }
     $compressionMethod = 0;
     if ($isVirtual) {
         Factory::getLog()->log(LogLevel::DEBUG, "-- Adding {$targetName} to archive (virtual data)");
     } else {
         Factory::getLog()->log(LogLevel::DEBUG, "-- Adding {$targetName} to archive (source: {$sourceNameOrData})");
     }
     if (!$configuration) {
         $configuration = Factory::getConfiguration();
     }
     $timer = Factory::getTimer();
     // Initialize inode change timestamp
     $filectime = 0;
     // Open data file for output
     if (is_null($this->fp)) {
         $this->fp = $this->_fopen($this->_dataFileName, "ab");
     }
     if ($this->fp === false) {
         $this->fp = null;
         $this->setError("Could not open archive file '{$this->_dataFileName}' for append!");
         return false;
     }
     if (!$configuration->get('volatile.engine.archiver.processingfile', false)) {
         // Uncache data -- WHY DO THAT?!
         /**
          * $configuration->set('volatile.engine.archiver.sourceNameOrData', null);
          * $configuration->set('volatile.engine.archiver.unc_len', null);
          * $configuration->set('volatile.engine.archiver.resume', null);
          * $configuration->set('volatile.engine.archiver.processingfile',false);
          * /**/
         // See if it's a directory
         $isDir = $isVirtual ? false : is_dir($sourceNameOrData);
         // See if it's a symlink (w/out dereference)
         $isSymlink = false;
         if ($this->_symlink_store_target && !$isVirtual) {
             $isSymlink = is_link($sourceNameOrData);
         }
         // Get real size before compression
         if ($isVirtual) {
             $fileSize = akstringlen($sourceNameOrData);
             $filectime = time();
         } else {
             if ($isSymlink) {
                 $fileSize = akstringlen(@readlink($sourceNameOrData));
             } else {
                 // Is the file readable?
                 if (!is_readable($sourceNameOrData) && !$isDir) {
                     // Unreadable files won't be recorded in the archive file
                     $this->setWarning('Unreadable file ' . $sourceNameOrData . '. Check permissions');
                     return false;
                 }
                 // Get the filesize
                 $fileSize = $isDir ? 0 : @filesize($sourceNameOrData);
                 $filectime = $isDir ? 0 : @filemtime($sourceNameOrData);
             }
         }
         // Decide if we will compress
         if ($isDir || $isSymlink) {
             $compressionMethod = 0;
             // don't compress directories...
         } else {
             if (!$memLimit || $fileSize >= _AKEEBA_COMPRESSION_THRESHOLD) {
                 // No memory limit, or over 1Mb files => always compress up to 1Mb files (otherwise it times out)
                 $compressionMethod = $fileSize <= _AKEEBA_COMPRESSION_THRESHOLD ? 1 : 0;
             } elseif (function_exists("memory_get_usage")) {
                 // PHP can report memory usage, see if there's enough available memory; the containing application / CMS alone eats about 5-6Mb. This code is called on files <= 1Mb
                 $availableRAM = $memLimit - memory_get_usage();
                 $compressionMethod = $availableRAM / 2.5 >= $fileSize ? 1 : 0;
             } else {
                 // PHP can't report memory usage, compress only files up to 512Kb (conservative approach) and hope it doesn't break
                 $compressionMethod = $fileSize <= 524288 ? 1 : 0;
//.........这里部分代码省略.........
开发者ID:jvhost,项目名称:A-Website,代码行数:101,代码来源:Jpa.php

示例6: partsize

 /**
  * Creates a dummy file of a given size. Remember to give the filesize
  * query parameter in bytes!
  */
 public function partsize()
 {
     $timer = Factory::getTimer();
     $blocks = $this->input->get('blocks', 1, 'int');
     $result = $this->createTempFile($blocks);
     if ($result) {
         // Save the setting
         if ($blocks > 200) {
             $blocks = 16383;
             // Over 25Mb = 2Gb minus 128Kb limit (safe setting for PHP not running on 64-bit Linux)
         }
         $profile_id = Platform::getInstance()->get_active_profile();
         $config = Factory::getConfiguration();
         $config->set('engine.archiver.common.part_size', $blocks * 128 * 1024);
         Platform::getInstance()->save_configuration($profile_id);
     }
     // Enforce the min exec time
     $timer->enforce_min_exec_time(false);
     return $result;
 }
开发者ID:kidaa30,项目名称:lojinha,代码行数:24,代码来源:confwiz.php

示例7: stepDatabaseDump


//.........这里部分代码省略.........
             // We are dumping data from a table, get the row count
             $this->getRowCount($tableAbstract);
         } else {
             // We should not dump any data
             Factory::getLog()->log(LogLevel::INFO, "Skipping dumping data of " . $tableAbstract);
             $this->maxRange = 0;
             $this->nextRange = 1;
             $outData = '';
             $numRows = 0;
             $dump_records = false;
         }
         // Output any data preamble commands, e.g. SET IDENTITY_INSERT for SQL Server
         if ($dump_records && Factory::getEngineParamsProvider()->getScriptingParameter('db.dropstatements', 0)) {
             Factory::getLog()->log(LogLevel::DEBUG, "Writing data dump preamble for " . $tableAbstract);
             $preamble = $this->getDataDumpPreamble($tableAbstract, $tableName, $this->maxRange);
             if (!empty($preamble)) {
                 if (!$this->writeDump($preamble)) {
                     return;
                 }
             }
         }
         // Get the table's auto increment information
         if ($dump_records) {
             $this->setAutoIncrementInfo();
         }
     }
     // Check if we have more work to do on this table
     $configuration = Factory::getConfiguration();
     $batchsize = intval($configuration->get('engine.dump.common.batchsize', 1000));
     if ($batchsize <= 0) {
         $batchsize = 1000;
     }
     if ($this->nextRange < $this->maxRange) {
         $timer = Factory::getTimer();
         // Get the number of rows left to dump from the current table
         $sql = $db->getQuery(true)->select('*')->from($db->nameQuote($tableAbstract));
         if (!is_null($this->table_autoincrement['field'])) {
             $sql->order($db->qn($this->table_autoincrement['field']) . ' ASC');
         }
         if ($this->nextRange == 0) {
             // First run, get a cursor to all records
             $db->setQuery($sql, 0, $batchsize);
             Factory::getLog()->log(LogLevel::INFO, "Beginning dump of " . $tableAbstract);
         } else {
             // Subsequent runs, get a cursor to the rest of the records
             $this->setSubstep($this->nextRange . ' / ' . $this->maxRange);
             // If we have an auto_increment value and the table has over $batchsize records use the indexed select instead of a plain limit
             if (!is_null($this->table_autoincrement['field']) && !is_null($this->table_autoincrement['value'])) {
                 Factory::getLog()->log(LogLevel::INFO, "Continuing dump of " . $tableAbstract . " from record #{$this->nextRange} using auto_increment column {$this->table_autoincrement['field']} and value {$this->table_autoincrement['value']}");
                 $sql->where($db->qn($this->table_autoincrement['field']) . ' > ' . $db->q($this->table_autoincrement['value']));
                 $db->setQuery($sql, 0, $batchsize);
             } else {
                 Factory::getLog()->log(LogLevel::INFO, "Continuing dump of " . $tableAbstract . " from record #{$this->nextRange}");
                 $db->setQuery($sql, $this->nextRange, $batchsize);
             }
         }
         $this->query = '';
         $numRows = 0;
         $use_abstract = Factory::getEngineParamsProvider()->getScriptingParameter('db.abstractnames', 1);
         $filters = Factory::getFilters();
         $mustFilter = $filters->hasFilterType('dbobject', 'children');
         try {
             $cursor = $db->query();
         } catch (\Exception $exc) {
             $db->resetErrors();
             $cursor = null;
开发者ID:jvhost,项目名称:A-Website,代码行数:67,代码来源:Mysql.php

示例8: tick

 /**
  * The public interface to an engine part. This method takes care for
  * calling the correct method in order to perform the initialisation -
  * run - finalisation cycle of operation and return a proper response array.
  *
  * @param   int  $nesting
  *
  * @return  array  A response array
  */
 public function tick($nesting = 0)
 {
     $this->waitTimeMsec = 0;
     $configuration = Factory::getConfiguration();
     $timer = Factory::getTimer();
     // Call the right action method, depending on engine part state
     switch ($this->getState()) {
         case "init":
             $this->_prepare();
             break;
         case "prepared":
             $this->_run();
             break;
         case "running":
             $this->_run();
             break;
         case "postrun":
             $this->_finalize();
             break;
     }
     // If there is still time, we are not finished and there is no break flag set, re-run the tick()
     // method.
     $breakFlag = $configuration->get('volatile.breakflag', false);
     if (!in_array($this->getState(), array('finished', 'error')) && $timer->getTimeLeft() > 0 && !$breakFlag && $nesting < 20 && $this->nest_logging) {
         // Nesting is only applied if $this->nest_logging == true (currently only Kettenrad has this)
         $nesting++;
         if ($this->nest_logging) {
             Factory::getLog()->log(LogLevel::DEBUG, "*** Batching successive steps (nesting level {$nesting})");
         }
         $out = $this->tick($nesting);
     } else {
         // Return the output array
         $out = $this->_makeReturnTable();
         // Things to do for nest-logged parts (currently, only Kettenrad is)
         if ($this->nest_logging) {
             if ($breakFlag) {
                 Factory::getLog()->log(LogLevel::DEBUG, "*** Engine steps batching: Break flag detected.");
             }
             // Reset the break flag
             $configuration->set('volatile.breakflag', false);
             // Log that we're breaking the step
             Factory::getLog()->log(LogLevel::DEBUG, "*** Batching of engine steps finished. I will now return control to the caller.");
             // Do I need client-side sleep?
             $serverSideSleep = true;
             if (method_exists($this, 'getTag')) {
                 $tag = $this->getTag();
                 $clientSideSleep = Factory::getConfiguration()->get('akeeba.basic.clientsidewait', 0);
                 if (in_array($tag, array('backend', 'restorepoint')) && $clientSideSleep) {
                     $serverSideSleep = false;
                 }
             }
             // Enforce minimum execution time
             $timer = Factory::getTimer();
             $this->waitTimeMsec = (int) $timer->enforce_min_exec_time(true, $serverSideSleep);
         }
     }
     // Send a Return Table back to the caller
     return $out;
 }
开发者ID:jvhost,项目名称:A-Website,代码行数:68,代码来源:Part.php

示例9: setUpAkeebaRestore

 /**
  * Set up the Akeeba Restore engine for the current archive
  */
 private function setUpAkeebaRestore()
 {
     $config = Factory::getConfiguration();
     $maxTime = Factory::getTimer()->getTimeLeft();
     $maxTime = floor($maxTime);
     $maxTime = max(2, $maxTime);
     $statistics = Factory::getStatistics();
     $stat = $statistics->getRecord();
     $backup_parts = Factory::getStatistics()->get_all_filenames($stat, false);
     $filePath = array_shift($backup_parts);
     $specialDirs = Platform::getInstance()->get_stock_directories();
     $tmpPath = $specialDirs['[SITETMP]'];
     $archiver = Factory::getArchiverEngine();
     $extension = $archiver->getExtension();
     $extension = strtoupper($extension);
     $extension = ltrim($extension, '.');
     $ksOptions = array('kickstart.tuning.max_exec_time' => $maxTime, 'kickstart.tuning.run_time_bias' => $config->get('akeeba.tuning.run_time_bias', 75), 'kickstart.tuning.min_exec_time' => '0', 'kickstart.procengine' => 'direct', 'kickstart.setup.sourcefile' => $filePath, 'kickstart.setup.destdir' => $tmpPath, 'kickstart.setup.restoreperms' => '0', 'kickstart.setup.filetype' => $extension, 'kickstart.setup.dryrun' => '1', 'kickstart.jps.password' => $config->get('engine.archiver.jps.key', '', false));
     \AKFactory::nuke();
     foreach ($ksOptions as $k => $v) {
         \AKFactory::set($k, $v);
     }
     \AKFactory::set('kickstart.enabled', true);
 }
开发者ID:esorone,项目名称:efcpw,代码行数:26,代码来源:TestExtract.php

示例10: _run

 /**
  * Implements the _run() abstract method
  */
 protected function _run()
 {
     // Check if we are already done
     if ($this->getState() == 'postrun') {
         Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Already finished");
         $this->setStep("");
         $this->setSubstep("");
         return;
     }
     // Mark ourselves as still running (we will test if we actually do towards the end ;) )
     $this->setState('running');
     // Check if we are still adding a database dump part to the archive, or if
     // we have to post-process a part
     if (Factory::getEngineParamsProvider()->getScriptingParameter('db.saveasname', 'normal') != 'output') {
         $archiver = Factory::getArchiverEngine();
         $configuration = Factory::getConfiguration();
         if ($configuration->get('engine.postproc.common.after_part', 0)) {
             if (!empty($archiver->finishedPart)) {
                 $filename = array_shift($archiver->finishedPart);
                 Factory::getLog()->log(LogLevel::INFO, 'Preparing to post process ' . basename($filename));
                 $timer = Factory::getTimer();
                 $startTime = $timer->getRunningTime();
                 $post_proc = Factory::getPostprocEngine();
                 $result = $post_proc->processPart($filename);
                 $this->propagateFromObject($post_proc);
                 if ($result === false) {
                     Factory::getLog()->log(LogLevel::WARNING, 'Failed to process file ' . $filename);
                     Factory::getLog()->log(LogLevel::WARNING, 'Error received from the post-processing engine:');
                     Factory::getLog()->log(LogLevel::WARNING, implode("\n", array_merge($this->getWarnings(), $this->getErrors())));
                     $this->setWarning('Failed to process file ' . basename($filename));
                 } elseif ($result === true) {
                     // Add this part's size to the volatile storage
                     $volatileTotalSize = $configuration->get('volatile.engine.archiver.totalsize', 0);
                     $volatileTotalSize += (int) @filesize($filename);
                     $configuration->set('volatile.engine.archiver.totalsize', $volatileTotalSize);
                     Factory::getLog()->log(LogLevel::INFO, 'Successfully processed file ' . basename($filename));
                 } else {
                     // More work required
                     Factory::getLog()->log(LogLevel::INFO, 'More post-processing steps required for file ' . $filename);
                     $configuration->set('volatile.postproc.filename', $filename);
                     // Let's push back the file into the archiver stack
                     array_unshift($archiver->finishedPart, $filename);
                     // Do we need to break the step?
                     $endTime = $timer->getRunningTime();
                     $stepTime = $endTime - $startTime;
                     $timeLeft = $timer->getTimeLeft();
                     if ($timeLeft < $stepTime) {
                         // We predict that running yet another step would cause a timeout
                         $configuration->set('volatile.breakflag', true);
                     } else {
                         // We have enough time to run yet another step
                         $configuration->set('volatile.breakflag', false);
                     }
                 }
                 // Should we delete the file afterwards?
                 if ($configuration->get('engine.postproc.common.delete_after', false) && $post_proc->allow_deletes && $result === true) {
                     Factory::getLog()->log(LogLevel::DEBUG, 'Deleting already processed file ' . basename($filename));
                     Platform::getInstance()->unlink($filename);
                 }
                 if ($post_proc->break_after) {
                     $configuration->set('volatile.breakflag', true);
                     return;
                 }
             }
         }
         if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
             // We had already started archiving the db file, but it needs more time
             $finished = true;
             Factory::getLog()->log(LogLevel::DEBUG, "Continuing adding the SQL dump part to the archive");
             $archiver->addFile(null, null, null);
             $this->propagateFromObject($archiver);
             if ($this->getError()) {
                 return;
             }
             $finished = !$configuration->get('volatile.engine.archiver.processingfile', false);
             if ($finished) {
                 $this->getNextDumpPart();
             } else {
                 return;
             }
         }
     }
     $this->stepDatabaseDump();
     $null = null;
     $this->writeline($null);
 }
开发者ID:AlexanderKri,项目名称:joom-upd,代码行数:89,代码来源:Base.php

示例11: putDataFromFileIntoArchive

 /**
  * Put up to $fileLength bytes of the file pointer $sourceFilePointer into the backup archive. Returns true if we
  * ran out of time and need to perform a step break. Returns false when the whole quantity of data has been copied.
  * Throws an ErrorException if soemthing really bad happens.
  *
  * @param   resource  $sourceFilePointer  The pointer to the input file
  * @param   int       $fileLength         How many bytes to copy
  *
  * @return  bool  True to indicate we need to resume packing the file in the next step
  */
 private function putDataFromFileIntoArchive(&$sourceFilePointer, &$fileLength)
 {
     // Get references to engine objects we're going to be using
     $configuration = Factory::getConfiguration();
     $timer = Factory::getTimer();
     // Quick copy data into the archive, AKEEBA_CHUNK bytes at a time
     while (!feof($sourceFilePointer) && $timer->getTimeLeft() > 0 && $fileLength > 0) {
         // Normally I read up to AKEEBA_CHUNK bytes at a time
         $chunkSize = AKEEBA_CHUNK;
         // Do I have a split ZIP?
         if ($this->useSplitArchive) {
             // I must only read up to the free space in the part file if it's less than AKEEBA_CHUNK.
             $free_space = $this->getPartFreeSize();
             $chunkSize = min($free_space, AKEEBA_CHUNK);
             // If I ran out of free space I have to create a new part file.
             if ($free_space <= 0) {
                 $this->createAndOpenNewPart();
                 // We have created the part. If the user asked for immediate post-proc, break step now.
                 if ($configuration->get('engine.postproc.common.after_part', 0)) {
                     $resumeOffset = @ftell($sourceFilePointer);
                     @fclose($sourceFilePointer);
                     $configuration->set('volatile.engine.archiver.resume', $resumeOffset);
                     $configuration->set('volatile.engine.archiver.processingfile', true);
                     $configuration->set('volatile.breakflag', true);
                     // Always close the open part when immediate post-processing is requested
                     @$this->fclose($this->fp);
                     $this->fp = null;
                     return true;
                 }
                 // No immediate post-proc. Recalculate the optimal chunk size.
                 $free_space = $this->getPartFreeSize();
                 $chunkSize = min($free_space, AKEEBA_CHUNK);
             }
         }
         // Read some data and write it to the backup archive part file
         $data = fread($sourceFilePointer, $chunkSize);
         $bytesWritten = $this->fwrite($this->fp, $data, akstrlen($data));
         // Subtract the written bytes from the bytes left to write
         $fileLength -= $bytesWritten;
     }
     /**
      * According to the file size we read when we were writing the file header we have more data to write. However,
      * we reached the end of the file. This means the file went away or shrunk. We can't reliably go back and
      * change the file header since it may be in a previous part file that's already been post-processed. All we can
      * do is try to warn the user.
      */
     while (feof($sourceFilePointer) && $timer->getTimeLeft() > 0 && $fileLength > 0) {
         throw new ErrorException('The file shrunk or went away while putting it in the backup archive. Your archive is damaged! If this is a temporary or cache file we advise you to exclude the contents of the temporary / cache folder it is contained in.');
     }
     // WARNING!!! The extra $unc_len != 0 check is necessary as PHP won't reach EOF for 0-byte files.
     if (!feof($sourceFilePointer) && $fileLength != 0) {
         // We have to break, or we'll time out!
         $resumeOffset = @ftell($sourceFilePointer);
         @fclose($sourceFilePointer);
         $configuration->set('volatile.engine.archiver.resume', $resumeOffset);
         $configuration->set('volatile.engine.archiver.processingfile', true);
         return true;
     }
     return false;
 }
开发者ID:AlexanderKri,项目名称:joom-upd,代码行数:70,代码来源:BaseArchiver.php

示例12: _addFile


//.........这里部分代码省略.........
                             $this->fp = null;
                             // Create new part if required
                             if (!$this->_createNewPart()) {
                                 // Die if we couldn't create the new part
                                 $this->setError('Could not create new ZIP part file ' . basename($this->_dataFileName));
                                 return false;
                             }
                             // Open data file for output
                             $this->fp = @$this->_fopen($this->_dataFileName, "ab");
                             if ($this->fp === false) {
                                 $this->setError("Could not open archive file {$this->_dataFileName} for append!");
                                 return false;
                             }
                             // Get the rest of the compressed data
                             $zdata = substr($sourceNameOrData, -$rest_size);
                         }
                         $bytes_left = $rest_size;
                     }
                 }
             }
         } else {
             // IMPORTANT! Only this case can be spanned across steps: uncompressed, non-virtual data
             if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
                 $sourceNameOrData = $configuration->get('volatile.engine.archiver.sourceNameOrData', '');
                 $unc_len = $configuration->get('volatile.engine.archiver.unc_len', 0);
                 $resume = $configuration->get('volatile.engine.archiver.resume', 0);
             }
             // Copy the file contents, ignore directories
             $zdatafp = @fopen($sourceNameOrData, "rb");
             if ($zdatafp === false) {
                 $this->setWarning('Unreadable file ' . $sourceNameOrData . '. Check permissions');
                 return false;
             } else {
                 $timer = Factory::getTimer();
                 // Seek to the resume point if required
                 if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
                     // Seek to new offset
                     $seek_result = @fseek($zdatafp, $resume);
                     if ($seek_result === -1) {
                         // What?! We can't resume!
                         $this->setError(sprintf('Could not resume packing of file %s. Your archive is damaged!', $sourceNameOrData));
                         return false;
                     }
                     // Doctor the uncompressed size to match the remainder of the data
                     $unc_len = $unc_len - $resume;
                 }
                 if (!$this->_useSplitZIP) {
                     // For non Split ZIP, just dump the file very fast
                     while (!feof($zdatafp) && $timer->getTimeLeft() > 0 && $unc_len > 0) {
                         $zdata = fread($zdatafp, AKEEBA_CHUNK);
                         $this->_fwrite($this->fp, $zdata, min(function_exists('mb_strlen') ? mb_strlen($zdata, '8bit') : strlen($zdata), AKEEBA_CHUNK));
                         $unc_len -= AKEEBA_CHUNK;
                         if ($this->getError()) {
                             return false;
                         }
                     }
                     if (!feof($zdatafp) && $unc_len != 0) {
                         // We have to break, or we'll time out!
                         $resume = @ftell($zdatafp);
                         $configuration->set('volatile.engine.archiver.resume', $resume);
                         $configuration->set('volatile.engine.archiver.processingfile', true);
                         return true;
                     }
                 } else {
                     // Split ZIP - Do we have enough space to host the whole file?
                     clearstatcache();
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:67,代码来源:Zip.php


注:本文中的Akeeba\Engine\Factory::getTimer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。