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


PHP Process::setIdleTimeout方法代码示例

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


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

示例1: createProcess

 /**
  * Creates new Symfony process with given arguments.
  *
  * @param string       $commandline  The command line to run.
  * @param integer|null $idle_timeout Idle timeout.
  *
  * @return Process
  */
 public function createProcess($commandline, $idle_timeout = null)
 {
     $process = new Process($commandline);
     $process->setTimeout(null);
     $process->setIdleTimeout($idle_timeout);
     return $process;
 }
开发者ID:console-helpers,项目名称:svn-buddy,代码行数:15,代码来源:ProcessFactory.php

示例2: testHttpDataDownloadUsingManyWorkers

 public function testHttpDataDownloadUsingManyWorkers()
 {
     $filesystem = new Filesystem();
     $targetDirPath = TEMP_DIR . '/' . uniqid('test_http_download');
     $filesystem->mkdir($targetDirPath);
     $workersManager = new Process('php ' . BIN_DIR . '/spider.php worker:start-many -c 3');
     $workersManager->start();
     $this->assertTrue($workersManager->isRunning(), 'Workers Manager should be working');
     $collector = new Process('php ' . BIN_DIR . '/spider.php collector:start --target-folder=' . $targetDirPath);
     $collector->setIdleTimeout(10);
     // there should be an output/result at least once every 10 seconds
     $collector->start();
     $this->assertTrue($collector->isRunning(), 'Task Results Collector should be working');
     $taskLoader = new Process('php ' . BIN_DIR . '/spider.php tasks:load < ' . FIXTURES_DIR . '/uris.txt');
     $taskLoader->setTimeout(120);
     // 120 seconds is enough to complete the task
     $taskLoader->start();
     $this->assertTrue($taskLoader->isRunning(), 'Task Loader should be working');
     while ($taskLoader->isRunning()) {
         sleep(1);
         // waiting for process to complete
     }
     $taskLoaderOutput = $taskLoader->getOutput() . $taskLoader->getErrorOutput();
     $this->assertContains('Total count of Tasks put in the Queue: 10', $taskLoaderOutput, 'Task Loader should have loaded 10 Tasks');
     $this->assertContains('Waiting for acknowledgement from Task Result Collector', $taskLoaderOutput, 'Task Loader should have been waiting for Task Result Collector acknowledgement');
     $this->assertContains('Informing all workers to stop', $taskLoaderOutput, 'Task Loader should have inform Workers to stop');
     $fi = new \FilesystemIterator($targetDirPath, \FilesystemIterator::SKIP_DOTS);
     $this->assertEquals(10, iterator_count($fi), '10 Task Result Files expected');
 }
开发者ID:highestgoodlikewater,项目名称:spider-5,代码行数:29,代码来源:DownloadingDataViaHttpTest.php

示例3: mustRun

    public function mustRun(array $commands, $timeout = 60)
    {
        $command_format = <<<SHELL
echo {{ESCAPED_COMMAND}}
{{COMMAND}}
SHELL;
        $formatted_commands = $this->formatCommands($commands, $command_format);
        $shell = <<<SHELL
set -e
set -u

{$formatted_commands}
SHELL;
        $log_service = $this->log_service;
        $process = new Process($shell);
        $process->setTimeout($timeout);
        $process->setIdleTimeout($timeout);
        $process->mustRun(function ($type, $buffer) use($log_service) {
            if (Process::ERR === $type) {
                $this->log_service->error($buffer);
            } else {
                $this->log_service->info($buffer);
            }
        });
    }
开发者ID:lightster,项目名称:dnsmasq-mgmt,代码行数:25,代码来源:ProcessService.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $commandLine = $input->getArgument('command-line');
     if (!$this->tryParseChunkSize($input->getOption('chunk-size'), $chunkSize)) {
         $output->writeln('<error>Chunk size must be number optionally suffixed with k or M.</error>');
         return 1;
     }
     $model = $this->model;
     if ($id = $input->getOption('instance')) {
         if (!($entity = $model->getById($id))) {
             $output->writeln('<error>Rixxi\\Process\\Entities\\IProcess instance does not exist.</error>');
             return 1;
         }
     } else {
         $entity = $model->create($commandLine);
     }
     $process = new Process($commandLine);
     $process->setTimeout(NULL);
     $process->setIdleTimeout(NULL);
     $exitCode = $process->run(function ($type, $output) use($entity, $model, $chunkSize) {
         if (strlen($output) > $chunkSize) {
             $output = str_split($output, $chunkSize);
         } else {
             $output = array($output);
         }
         foreach ($output as $chunk) {
             $model->append($entity, $chunk, $type === Process::ERR);
         }
     });
     $model->finish($entity, $exitCode);
 }
开发者ID:rixxi,项目名称:watch-process,代码行数:31,代码来源:WatchCommand.php

示例5: run

 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("Running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             print $buffer;
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
开发者ID:stefanhuber,项目名称:Robo,代码行数:33,代码来源:Exec.php

示例6: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->printAction();
     $this->process = new Process($this->getCommand());
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             $progressWasVisible = $this->hideTaskProgress();
             print $buffer;
             $this->showTaskProgress($progressWasVisible);
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::fromException($this, $e);
     }
     return Result::success($this);
 }
开发者ID:jjok,项目名称:Robo,代码行数:36,代码来源:Exec.php

示例7: run

 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (!$this->background and !$this->isPrinted) {
         $this->process->run();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     if (!$this->background and $this->isPrinted) {
         $this->process->run(function ($type, $buffer) {
             Process::ERR === $type ? print 'ER» ' . $buffer : (print '» ' . $buffer);
         });
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
开发者ID:sliver,项目名称:Robo,代码行数:26,代码来源:Exec.php

示例8: runCommands

 public function runCommands()
 {
     $commands = implode('; ', $this->getCommands());
     $process = new Process($commands, $this->getPath());
     $process->setTimeout(600);
     $process->setIdleTimeout(null);
     $this->logger->info('Running "' . $process->getCommandLine() . '"');
     $process->mustRun();
 }
开发者ID:anorgan,项目名称:deployer-common,代码行数:9,代码来源:Local.php

示例9: create

 public static function create(callable $retryCallback, callable $killCallback, callable $successCallback, callable $errorCallback, Logger $logger)
 {
     return function ($command, QueueMessage $message, Job $job) use($retryCallback, $killCallback, $successCallback, $errorCallback, $logger) {
         $process = new Process($command);
         $process->setTimeout(86400);
         $process->setIdleTimeout(null);
         try {
             $process->run();
         } catch (ProcessTimedOutException $e) {
             $errorCallback($job, "Process timed out");
             return $process;
         } catch (RuntimeException $e) {
             // process has been signaled or some other error occurred, handled down in code
         }
         switch ($process->getExitCode()) {
             case self::JOB_EXIT_STATUS_LOCK:
             case self::OLD_JOB_EXIT_STATUS_LOCK:
                 $newMessageId = $retryCallback($job, $message);
                 $logger->info("DB is locked. Message requeued", ['jobId' => $job->getId(), 'oldMessageId' => $message->getId(), 'newMessageId' => $newMessageId, 'lockName' => $job->getLockName()]);
                 break;
             case JobCommand::STATUS_RETRY:
                 $message->incrementRetries();
                 if ($message->getRetryCount() > self::MAX_EXECUTION_RETRIES) {
                     $errorCallback($job, "Retries exceeded");
                     $logger->info("Maximum retries exceeded", ['jobId' => $job->getId(), 'messageId' => $message->getId()]);
                     break;
                 }
                 $newMessageId = $retryCallback($job, $message);
                 $logger->info("Retry due to an error. Message requeued", ['jobId' => $job->getId(), 'oldMessageId' => $message->getId(), 'newMessageId' => $newMessageId]);
                 break;
             case 137:
             case 143:
                 // process has been signaled
                 $killCallback($job);
                 $logger->info("Process has been killed", ['jobId' => $job->getId(), 'messageId' => $message->getId()]);
                 break;
             case JobCommand::STATUS_SUCCESS:
                 $successCallback();
                 $logger->info("Process finished successfully", ['jobId' => $job->getId(), 'messageId' => $message->getId()]);
                 break;
             case JobCommand::STATUS_ERROR:
             default:
                 $errorCallback($job, $process->getOutput());
                 $logger->info("Process finished with an error", ['jobId' => $job->getId(), 'messageId' => $message->getId()]);
                 break;
         }
         return $process;
     };
 }
开发者ID:keboola,项目名称:syrup-queue,代码行数:49,代码来源:LegacyStrategy.php

示例10: run

 public function run($task, $live = false)
 {
     $result = [];
     $process = new Process('~/.composer/vendor/bin/envoy run ' . $task);
     $process->setTimeout(3600);
     $process->setIdleTimeout(300);
     $process->setWorkingDirectory(base_path());
     $process->run(function ($type, $buffer) use($live, &$result) {
         $buffer = str_replace('[127.0.0.1]: ', '', $buffer);
         if ($live) {
             echo $buffer . '</br />';
         }
         $result[] = $buffer;
     });
     return $result;
 }
开发者ID:NukaCode,项目名称:dasher,代码行数:16,代码来源:Envoy.php

示例11: runProcess

 /**
  * @param BackgroundCommand $command
  * @return string
  */
 protected function runProcess(BackgroundCommand $command)
 {
     $binary = $this->getBackgroundHandlerBinary();
     $path = $this->getBackgroundHandlerPath();
     $route = $this->getBackgroundHandlerRoute();
     $arguments = implode(' ', $this->getBackgroundHandlerArguments($command));
     $binaryArguments = implode(' ', $this->backgroundHandlerBinaryArguments);
     $process = new Process("{$binary} {$binaryArguments} {$path} {$route} {$arguments}");
     $process->setTimeout($this->backgroundProcessTimeout);
     $process->setIdleTimeout($this->backgroundProcessIdleTimeout);
     if ($command->isAsync()) {
         $process->start();
     } else {
         $process->run();
     }
     return $process;
 }
开发者ID:trntv,项目名称:yii2-command-bus,代码行数:21,代码来源:BackgroundCommandMiddleware.php

示例12: exec

 /**
  * Executes a command.
  * When no working directory is passed, the project directory is used.
  *
  * @param string   $command  The command line to run
  * @param string   $cwd      The working directory or null to use the project directory
  * @param int      $timeout  The process timeout (max. runtime). To disable set to null.
  * @param callable $callback A PHP callback to run whenever there is some output available on STDOUT or STDERR
  *
  * @return Process
  */
 public function exec($command, $cwd = null, $timeout = 60, $callback = null)
 {
     \Assert\that($command)->string()->notEmpty();
     \Assert\that($cwd)->nullOr()->string()->notEmpty();
     \Assert\that($timeout)->nullOr()->integer()->min(5);
     if (!is_null($callback) && !is_callable($callback)) {
         throw new \InvalidArgumentException('Given callback must be a callable.');
     }
     $cwd = $this->prepareWorkingDirectory($cwd);
     $callback = $this->prepareCallback($callback);
     $process = new Process($command, $cwd);
     $process->setTimeout($timeout);
     $process->setIdleTimeout($timeout);
     $this->logger->debug(sprintf("Executing command '%s' in '%s', timeout %s seconds", $command, $cwd, $timeout));
     $process->run($callback);
     return $process;
 }
开发者ID:mykanoa,项目名称:kanoa,代码行数:28,代码来源:LocalTask.php

示例13: execute

 public function execute($command, array $cpu = null)
 {
     $fs = new Filesystem();
     $tempfile = tempnam(sys_get_temp_dir(), '');
     if (file_exists($tempfile)) {
         unlink($tempfile);
     }
     $fs->mkdir($tempfile);
     $process = new Process($command, $tempfile);
     $process->setTimeout(null);
     $process->setIdleTimeout(null);
     $process->run();
     $fs->remove($tempfile);
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     //TODO mix strerr and strout.
     return sprintf("%s\n%s", $process->getOutput(), $process->getErrorOutput());
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:19,代码来源:LocalExecutor.php

示例14: applyPhpPatch

/**
 * @param DBPatcher\PatchFile $patchFile
 * @param \Symfony\Component\Process\Process $process
 * @param resource $stdout
 * @param resource $stderr
 * @return DBPatcher\PatchFile
 */
function applyPhpPatch($patchFile, $process, $stdout = null, $stderr = null)
{
    if ($patchFile->extension === 'php') {
        $process->setTimeout(null);
        $process->setIdleTimeout(null);
        $process->setCommandLine('/usr/bin/env php ' . $patchFile->filename);
        $process->start(function ($type, $buffer) use($stdout, $stderr) {
            $pipe = $type === Process::ERR && is_resource($stderr) ? $stderr : $stdout;
            if ($pipe) {
                fputs($pipe, $buffer);
            }
        });
        if ($process->wait() === 0) {
            return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_INSTALLED));
        } else {
            return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR), $process->getErrorOutput());
        }
    }
    return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR));
}
开发者ID:jamayka,项目名称:db-patcher,代码行数:27,代码来源:functions.php

示例15: create

 public static function create(Lock $lock, callable $retryCallback, callable $killCallback, callable $successCallback, callable $errorCallback)
 {
     return function ($command, QueueMessage $message, Job $job) use($lock, $retryCallback, $killCallback, $successCallback, $errorCallback) {
         if (!$lock->lock()) {
             $retryCallback($message, "DB is locked");
         }
         $process = new Process($command);
         $process->setTimeout(86400);
         $process->setIdleTimeout(null);
         try {
             $process->run();
         } catch (ProcessTimedOutException $e) {
             $errorCallback($job, "Process timed out");
         } catch (RuntimeException $e) {
             // process has been signaled or some other error occurred, handled down in code
         }
         switch ($process->getExitCode()) {
             case JobCommand::STATUS_RETRY:
                 $message->incrementRetries();
                 if ($message->getRetryCount() > self::MAX_EXECUTION_RETRIES) {
                     $errorCallback($job, "Retries exceeded");
                     break;
                 }
                 $retryCallback($message);
                 break;
             case 137:
             case 143:
                 // process has been signaled
                 $killCallback($job);
                 break;
             case JobCommand::STATUS_SUCCESS:
                 $successCallback();
                 break;
             case JobCommand::STATUS_ERROR:
             default:
                 $errorCallback($job, $process->getOutput());
                 break;
         }
         return $process;
     };
 }
开发者ID:keboola,项目名称:syrup-queue,代码行数:41,代码来源:DefaultStrategy.php


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