當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Toolbox::checkMemoryLimit方法代碼示例

本文整理匯總了PHP中Toolbox::checkMemoryLimit方法的典型用法代碼示例。如果您正苦於以下問題:PHP Toolbox::checkMemoryLimit方法的具體用法?PHP Toolbox::checkMemoryLimit怎麽用?PHP Toolbox::checkMemoryLimit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Toolbox的用法示例。


在下文中一共展示了Toolbox::checkMemoryLimit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: launch

 /**
  * Launch the need cron tasks
  *
  * @param $mode   (internal/external, <0 to force)
  * @param $max    number of task to launch (default 1)
  * @param $name   of task to run (default '')
  *
  * @return the name of last task launched
  **/
 public static function launch($mode, $max = 1, $name = '')
 {
     global $CFG_GLPI;
     // No cron in maintenance mode
     if (isset($CFG_GLPI['maintenance_mode']) && $CFG_GLPI['maintenance_mode']) {
         return false;
     }
     $crontask = new self();
     $taskname = '';
     if (abs($mode) == self::MODE_EXTERNAL) {
         // If cron is launched in command line, and if memory is insufficient,
         // display a warning in the logs
         if (Toolbox::checkMemoryLimit() == 2) {
             Toolbox::logInFile('cron', __('A minimum of 64 Mio is commonly required for GLPI.') . "\n");
         }
         // If no task in CLI mode, call cron.php from command line is not really usefull ;)
         if (!countElementsInTable($crontask->getTable(), ['mode' => abs($mode)])) {
             Toolbox::logInFile('cron', __('No task with Run mode = CLI, fix your tasks configuration') . "\n");
         }
     }
     if (self::get_lock()) {
         for ($i = 1; $i <= $max; $i++) {
             $prefix = abs($mode) == self::MODE_EXTERNAL ? __('External') : __('Internal');
             if ($crontask->getNeedToRun($mode, $name)) {
                 $_SESSION["glpicronuserrunning"] = "cron_" . $crontask->fields['name'];
                 if ($plug = isPluginItemType($crontask->fields['itemtype'])) {
                     Plugin::load($plug['plugin'], true);
                 }
                 $fonction = array($crontask->fields['itemtype'], 'cron' . $crontask->fields['name']);
                 if (is_callable($fonction)) {
                     if ($crontask->start()) {
                         // Lock in DB + log start
                         $taskname = $crontask->fields['name'];
                         //TRANS: %1$s is mode (external or internal), %2$s is an order number,
                         $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i);
                         $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, sprintf(__('%1$s %2$s') . "\n", __('Launch'), $crontask->fields['name']));
                         Toolbox::logInFile('cron', $msgcron);
                         $retcode = call_user_func($fonction, $crontask);
                         $crontask->end($retcode);
                         // Unlock in DB + log end
                     } else {
                         $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i);
                         $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, sprintf(__('%1$s %2$s') . "\n", __("Can't start"), $crontask->fields['name']));
                         Toolbox::logInFile('cron', $msgcron);
                     }
                 } else {
                     if (is_array($fonction)) {
                         $fonction = implode('::', $fonction);
                     }
                     Toolbox::logInFile('php-errors', sprintf(__('Undefined function %s (for cron)') . "\n", $fonction));
                     $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i);
                     $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, sprintf(__('%1$s %2$s') . "\n", __("Can't start"), $crontask->fields['name']));
                     Toolbox::logInFile('cron', $msgcron . "\n" . sprintf(__('Undefined function %s (for cron)') . "\n", $fonction));
                 }
             } else {
                 if ($i == 1) {
                     $msgcron = sprintf(__('%1$s #%2$s'), $prefix, $i);
                     $msgcron = sprintf(__('%1$s: %2$s'), $msgcron, __('Nothing to launch'));
                     Toolbox::logInFile('cron', $msgcron . "\n");
                 }
             }
         }
         // end for
         $_SESSION["glpicronuserrunning"] = '';
         self::release_lock();
     } else {
         Toolbox::logInFile('cron', __("Can't get DB lock") . "\n");
     }
     return $taskname;
 }
開發者ID:glpi-project,項目名稱:glpi,代碼行數:79,代碼來源:crontask.class.php


注:本文中的Toolbox::checkMemoryLimit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。