/** * Creates a subprocess object * @param string! $args * @return Subprocess An object to communicate */ public static function popen($args) { $process = new self(); $process->args = $args; $process->start(); return $process; }
/** * Message box * * @param Window $parent * @param string $text * @param string $title * @return void */ public static function box(Window $parent, $text, $title) { $msg = new self($parent); $msg->setText($text); $msg->setTitle($title); $msg->start(); unset($msg); }
/** * Starts the repl using the given config options * @param array $config * Example: * <code> * array( * 'locals' => array( * 'varname1' => 'value1', * 'varname2' => 'value2', * ), * 'prompt' => 'promptstring> ', * ); * </code> * @return void * @author David Hazel <*****@*****.**> **/ public static function go(array $config = NULL) { if (!empty($config['prompt'])) { $prompt = $config['prompt']; } else { $prompt = 'php> '; } $boris = new self($prompt); if (!empty($config['locals'])) { foreach ($config['locals'] as $key => $value) { $boris->setLocal($key, $value); } } $boris->start(); }
/** * @param $nodes * * @return Node */ public static function buildTreeFromAwl($nodes) { $prevStep = false; $conj = false; $builder = new self(); foreach ($nodes as $node) { $key = key($node); $contents = current($node); if (is_array($contents)) { $contents = self::buildTreeFromAwl($contents); } $contents = [$contents]; if ($key === 'workflow') { $builder->add('workflow', $contents)->start(); continue; } if ($key === 'step') { if ($prevStep) { $builder->end(); } $prevStep = true; $builder->add('step', $contents)->start(); continue; } if ($key === 'conj') { $conj = true; $builder->start(); continue; } $builder->add($key, $contents); if ($conj) { $conj = false; $builder->end(); } } return $builder->retrieve(0); }
/** * 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; }
/** * Вызов компонента * @param string $componentName * @param string $templateName default: _default * @param array $arComponentParams * @param [object $obParentComponent] */ public static function call($componentName, $templateName, $arComponentParams, $obParentComponent = null) { /** * TODO: $obParentComponent - Для использования комплексных компонентов */ $component = new self(); try { return $component->start($componentName, $templateName, $arComponentParams, $obParentComponent); } catch (ComponentException $except) { echo 'Error: ' . $except->getMessage() . '.' . endl; } unset($component); }
/** * Static method to create your threads from functions ... **/ public static function call($method, $params) { $thread = new self($method, $params); if ($thread->start()) { return $thread; } /* else throw Nastyness **/ }
/** * 返回单例模式 */ public static function getInstance() { if (!is_null(self::$_instance)) { return self::$_instance; } $instance = new self(); $instance->start(); self::$_instance = $instance; return $instance; }
/** * Spawns a new forked process and runs it. * * @param callable $function A callable to invoke in the process. * * @return \Icicle\Concurrent\Forking\Fork The process object that was spawned. */ public static function spawn(callable $function, ...$args) : self { $fork = new self($function, ...$args); $fork->start(); return $fork; }
public static function of(Closure $closure, array $args = []) { $future = new self($closure, $args); $future->start(); return $future; }
/** * Spawns a new thread and runs it. * * @param callable $function The callable to invoke in the thread. * * @return Thread The thread object that was spawned. */ public static function spawn(callable $function, ...$args) { $thread = new self($function, ...$args); $thread->start(); return $thread; }
/** * Launch the need cron tasks * * @param $mode (internal/external, <0 to force) * @param $max number of task to launch () * @param $name of task to run * * @return the name of last task launched **/ public static function launch($mode, $max = 1, $name = '') { $taskname = ''; if (self::get_lock()) { $crontask = new self(); for ($i = 1; $i <= $max; $i++) { $prefix = ($mode == self::MODE_EXTERNAL ? 'External' : 'Internal') . " #{$i}: "; 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']; logInFile('cron', $prefix . "Launch " . $crontask->fields['name'] . "\n"); $retcode = call_user_func($fonction, $crontask); $crontask->end($retcode); // Unlock in DB + log end } else { logInFile('cron', $prefix . "Can't start " . $crontask->fields['name'] . "\n"); } } else { if (is_array($fonction)) { $fonction = implode('::', $fonction); } logInFile('php-errors', "Undefined function '{$fonction}' (for cron)\n"); logInFile('cron', $prefix . "Can't start " . $crontask->fields['name'] . "\nUndefined function '{$fonction}'\n"); } } else { if ($i == 1) { logInFile('cron', $prefix . "Nothing to launch\n"); } } } // end for $_SESSION["glpicronuserrunning"] = ''; self::release_lock(); } else { logInFile('cron', "Can't get DB lock'\n"); } return $taskname; }
public static function run($options) { $queueConfig = config('job'); if (!$queueConfig) { return false; } $obj = new \Kerisy\Job\Process(count($queueConfig)); $obj->workerStart = function (\swoole_process $worker) use($queueConfig) { if (!$queueConfig) { return false; } $worker->name("job server worker #" . $worker->id); $v = $queueConfig[$worker->id]; $worker = new self($v); $worker->start(); }; $obj->run($options); }
/** * Start the watchdog * The watchdog will fork and the child's control flow will continue after the WatchDog::run invocation. * If the child dies with an error return value, it is restarted. * Normal termination (exit(0);) will also terminate the watchdog or make him return True if $returnWhenFinished was enabled. * * @param bool $returnWhenFinished Whether WatchDog should return or exit(0) when child finished gracefully * @return bool False in child processes, True if $returnWhenFinished was set to True in parent process */ public static function run($returnWhenFinished = false) { $watchdog = new self(); $watchdog->processCallbacks['default'] = null; return $watchdog->start($returnWhenFinished); }