本文整理汇总了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;
}