本文整理汇总了PHP中Symfony\Component\Process\Process::getPid方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::getPid方法的具体用法?PHP Process::getPid怎么用?PHP Process::getPid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::getPid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$procApp = $input->getArgument('procApp');
$procCall = $input->getArgument('procCall');
$procArgs = $input->getArgument('processArgs');
$cmd = 'php ' . $procApp . ' ' . $procCall . ' ' . implode(' ', $procArgs);
$process = new Process($cmd);
$process->start();
echo 'PID: ' . $process->getPid() . "\n";
}
示例2: start
/**
* Starts the server
*
* @param array $options
* @return void
*/
public function start(array $options)
{
$verbose = isset($options['verbose']) && $options['verbose'];
if ($this->checkServer()) {
$this->output->writeln("<error>Queue Manager is already running.</error>");
return;
}
if ($verbose) {
$this->output->writeln("<info>Queue Manager is starting.</info>");
}
$phpFinder = new PhpExecutableFinder();
$phpPath = $phpFinder->find();
if ($options['daemon']) {
$command = $phpPath . ' app/console naroga:queue:start ' . ($verbose ? '-v' : '') . ' &';
$app = new Process($command);
$app->setTimeout(0);
$app->start();
$pid = $app->getPid();
$this->memcache->replace('queue.lock', $pid);
if ($verbose) {
$this->output->writeln('<info>Queue Manager started with PID = ' . ($pid + 1) . '.</info>');
}
return;
}
$this->registerListeners($verbose);
if ($verbose) {
$pid = $this->memcache->get('queue.lock');
$this->output->writeln('<info>Queue Manager started with PID = ' . $pid . '.</info>');
}
$this->resetServerConfig($options);
$this->processQueue($options);
}
示例3: startProcess
/**
* Starts a process in the background - waits for 1 second to check that the process did not die prematurely
* (it is supposed to be a long-running task)
* @param string $command
*
* @return int the pid of the created process
* @throws \Symfony\Component\Process\Exception\RuntimeException when process could not start / terminated immediately
*/
public function startProcess($command)
{
$process = new Process($command);
$process->start();
// give the OS some time to abort invalid commands
sleep(1);
if (!$process->isRunning()) {
throw new RuntimeException("Process terminated immediately");
}
// while at it, emit a message
if ($this->dispatcher) {
$event = new ProcessStartedEvent($process->getPid(), $command);
$this->dispatcher->dispatch(EventsList::PROCESS_STARTED, $event);
}
return $process->getPid();
}
示例4: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return bool
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$process = new Process($input->getArgument('argument'));
$process->start();
$pid = $process->getPid();
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
$entity_process = new \Monotype\Bundle\DirectControllBundle\Entity\Process();
$entity_process->setPid($process->getPid());
$entity_process->setScript($input->getArgument('argument'));
$entity_process->setUid('manual');
$entity_process->setDatetime(new \DateTime('now'));
$entityManager->persist($entity_process);
$entityManager->flush();
$output->writeln('Command "' . $input->getArgument('argument') . '" result:');
$output->writeln('PID: ' . $pid . PHP_EOL);
return true;
}
示例5: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return bool
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$process = new Process('watch df -h');
$process->start();
$pid = $process->getPid();
$output->writeln('Command result:');
$output->writeln('PID: ' . $pid . PHP_EOL);
return true;
}
示例6: newWorker
public function newWorker()
{
$queue = Input::get('queue');
$root = base_path();
$cmd = 'php artisan worker:start ' . $queue;
$p = new Symfony\Component\Process\Process($cmd, $root);
$p->start();
return Response::json(array('res' => 0, 'pid' => $p->getPid()));
}
示例7: start_proc
protected function start_proc(&$entry)
{
$process = new Process($entry["command"], $this->cwd, $this->env);
$process->start();
$entry["pid"] = $process->getPid();
$entry["process"] = $process;
if (empty($entry["pid"])) {
throw new \Exception($entry["name"] . " could not be run");
}
}
示例8: run
/**
* {@inheritdoc}
*/
public function run(JobReportInterface $report)
{
try {
$this->process->start();
$this->savePid($this->process->getPid(), $report);
while ($this->process->isRunning()) {
// waiting for process to finish
}
if ($this->process->isSuccessful()) {
$report->setOutput(trim($this->process->getOutput()));
return JobState::STATE_FINISHED;
}
$report->setErrorOutput(trim($this->process->getErrorOutput()));
} catch (LogicException $e) {
$report->setErrorOutput($e->getMessage());
} catch (RuntimeException $e) {
$report->setErrorOutput($e->getMessage());
}
return JobState::STATE_FAILED;
}
示例9: runChildProcess
/**
* Run child process.
*
* @param Daemonize $daemon
*
* @return mixed
*/
public function runChildProcess(Daemonize $daemon)
{
$this->output->setEnableAnsi(false);
$this->output->setStdOut($this->log);
$this->output->setStdErr($this->log);
$this->process->start();
if (!$this->process->isRunning()) {
throw new RuntimeException('Unable to start server process.');
}
$this->processControl->setPid($this->process->getPid());
$this->process->wait(function ($type, $buffer) {
$this->output->writeln($buffer);
});
}
示例10: startProcess
/**
* @param Process $process
* @param string $pidFile
* @param OutputInterface $log
*
* @throws \Exception on failure
*
* @return int
* The process PID.
*/
public function startProcess(Process $process, $pidFile, OutputInterface $log)
{
$this->processes[$pidFile] = $process;
try {
$process->start(function ($type, $buffer) use($log) {
$log->writeln($buffer);
});
} catch (\Exception $e) {
unset($this->processes[$pidFile]);
throw $e;
}
$pid = $process->getPid();
if (file_put_contents($pidFile, $pid) === false) {
throw new \RuntimeException('Failed to write PID file: ' . $pidFile);
}
$log->writeln(sprintf('Process started: %s', $process->getCommandLine()));
return $pid;
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$startTime = microtime(true);
$tables = $this->getContainer()->getParameter('tables');
$limit = (int) $input->getOption('limit');
$commands = [];
foreach (array_keys($tables['root']) as $root) {
$commands[] = "kp:scrap:page {$root}";
}
foreach ($tables['child'] as $root => $tables) {
foreach (array_keys($tables) as $child) {
$commands[] = "kp:scrap:sub:page {$root} {$child}";
}
}
/* @var $processes Process[] */
$processes = [];
foreach ($commands as $command) {
$processes[$command] = $process = new Process("app/console {$command} --limit={$limit}");
$output->writeln("start: <info>{$command}</info>");
$process->start();
}
while (true) {
foreach ($processes as $command => $process) {
if ($process->isRunning()) {
$output->writeln("Running {$command}: <info>{$process->getPid()}</info>");
} else {
$output->writeln("Finish <info>{$command}</info>:");
$output->writeln($process->getOutput());
$processes[$command] = $process->restart();
}
sleep(1);
}
$duration = microtime(true) - $startTime;
$output->writeln("<info>Time: {$duration}</info>");
}
}
示例12: runCommand
private function runCommand($string, $timeout = 0)
{
$entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTaskLog');
try {
$process = new Process($string);
$process->setTimeout($timeout);
$process->start(array($this, 'callbackProcess'));
$this->cronTaskLog->setPid($process->getPid());
$entityManager->persist($this->cronTaskLog);
$entityManager->flush();
$exitCode = $process->wait();
$this->cronTaskLog->setDateEnd(new \DateTime());
if ($exitCode > 0) {
$this->cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED);
} elseif ($process->getErrorOutput() != '') {
$this->cronTaskLog->setStatus(CronTaskLog::STATUS_WARNING);
} else {
$this->cronTaskLog->setStatus(CronTaskLog::STATUS_SUCCESS);
}
$this->cronTaskLog->setPid(null);
$entityManager->persist($this->cronTaskLog);
$entityManager->flush();
return $exitCode !== 0;
} catch (\Exception $e) {
$this->cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED);
$this->cronTaskLog->setPid(null);
$this->cronTaskLog->setDateEnd(new \DateTime());
$entityManager->persist($this->cronTaskLog);
$entityManager->flush();
return 1;
}
}
示例13: lock
/**
* Lock the event
*
* @param \Crunz\Event $event
*
* @return string
*/
protected function lock()
{
file_put_contents($this->lockFile(), $this->process->getPid());
}
示例14: runProcessAsync
/**
* @param $command
* @param bool $isRestore
*/
protected function runProcessAsync($command, $isRestore = false)
{
$process = new Process($command);
$process->start();
$pid = $process->getPid();
$activePids = Yii::$app->session->get('backupPids', []);
if (!$process->isRunning()) {
if ($process->isSuccessful()) {
$msg = !$isRestore ? Yii::t('dbManager', 'Dump successfully created.') : Yii::t('dbManager', 'Dump successfully restored.');
Yii::$app->session->addFlash('success', $msg);
} else {
$msg = !$isRestore ? Yii::t('dbManager', 'Dump failed.') : Yii::t('dbManager', 'Restore failed.');
Yii::$app->session->addFlash('error', $msg . '<br>' . 'Command - ' . $command . '<br>' . $process->getOutput() . $process->getErrorOutput());
Yii::error($msg . PHP_EOL . 'Command - ' . $command . PHP_EOL . $process->getOutput() . PHP_EOL . $process->getErrorOutput());
}
} else {
$activePids[$pid] = $command;
Yii::$app->session->set('backupPids', $activePids);
Yii::$app->session->addFlash('info', Yii::t('dbManager', 'Process running with pid={pid}', ['pid' => $pid]) . '<br>' . $command);
}
}
示例15: startDisplayProcess
public function startDisplayProcess()
{
if ($this->isWindows()) {
$cmd = null;
} else {
if ($this->getEnvVar('DISPLAY')) {
return true;
}
$this->setEnvVar('DISPLAY', ':99.0');
$cmd = '/sbin/start-stop-daemon --start --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16';
}
$output = new BufferedOutput();
$process = new Process($cmd, SeleniumSetup::$APP_ROOT_PATH, SeleniumSetup::$APP_PROCESS_ENV, null, null);
$process->run(function ($type, $line) use($output) {
$output->write($line);
});
//var_dump($process->getPid());
return $process->getPid();
}