- if ($this->mode->isBackend()) {
- $process = 'backend';
- $maxsysload = intval($this->config->get('system', 'maxloadavg'));
- if ($maxsysload < 1) {
- $maxsysload = 50;
- }
- } else {
- $process = 'frontend';
- $maxsysload = intval($this->config->get('system', 'maxloadavg_frontend'));
- if ($maxsysload < 1) {
- $maxsysload = 50;
- }
- }
-
- $load = Core\System::currentLoad();
- if ($load) {
- if (intval($load) > $maxsysload) {
- $this->logger->info('system load for process too high.', ['load' => $load, 'process' => $process, 'maxsysload' => $maxsysload]);
- return true;
- }
- }
- return false;
- }
-
- /**
- * Executes a child process with 'proc_open'
- *
- * @param string $command The command to execute
- * @param array $args Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ]
- *
- * @throws HTTPException\InternalServerErrorException
- */
- public function proc_run($command, $args)
- {
- if (!function_exists('proc_open')) {
- return;
- }
-
- $cmdline = $this->config->get('config', 'php_path', 'php') . ' ' . escapeshellarg($command);
-
- foreach ($args as $key => $value) {
- if (!is_null($value) && is_bool($value) && !$value) {
- continue;
- }
-
- $cmdline .= ' --' . $key;
- if (!is_null($value) && !is_bool($value)) {
- $cmdline .= ' ' . $value;
- }
- }
-
- if ($this->isMinMemoryReached()) {
- return;
- }
-
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
- $resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->getBasePath());
- } else {
- $resource = proc_open($cmdline . ' &', [], $foo, $this->getBasePath());
- }
- if (!is_resource($resource)) {
- $this->logger->debug('We got no resource for command.', ['cmd' => $cmdline]);
- return;
- }
- proc_close($resource);