本文整理汇总了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;
}
示例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');
}
示例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);
}
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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;
};
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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));
}
示例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;
};
}