本文整理汇总了PHP中Process::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::run方法的具体用法?PHP Process::run怎么用?PHP Process::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process::run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Runs the process.
*
* @param Closure|string|array $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @return integer The exit status code
*
* @api
*/
public function run($callback = null)
{
if (null === $this->getCommandLine()) {
$this->setCommandLine($this->getPhpBinary());
}
return parent::run($callback);
}
示例2: fork
public function fork(Process $children, $user_name = null, $group_name = null)
{
if ($this->allocateSHMPerChildren()) {
$children->setSHMSegment(new SHMCache(uniqid('process_manager;shm_per_children' . $children->getInternalId()), $this->allocateSHMPerChildren));
}
pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD));
$pid = pcntl_fork();
// Error
if ($pid == -1) {
throw new RuntimeException('pcntl_fork() returned -1, are you sure you are running the script from CLI?');
} else {
if (!$pid) {
if (!is_null($group_name)) {
if (!$this->setGroup($group_name)) {
throw new RuntimeException('set group_name failed. are you sure you have the privileges?');
}
}
if (!is_null($user_name)) {
if (!$this->setUser($user_name)) {
throw new RuntimeException('set user_name failed. are you sure you have the privileges?');
}
}
$children->run();
exit;
// redundant, added only for clarity
} else {
$children->setStarted(true);
$this->children[] = $children;
// Store the children's PID
$children->setPid($pid);
pcntl_sigprocmask(SIG_UNBLOCK, array(SIGCHLD));
}
}
}
示例3: __invoke
/**
* Invoke filter
* @param string $code
* @param \WebLoader\Compiler $loader
* @param string $file
* @return string
*/
public function __invoke($code, \WebLoader\Compiler $loader, $file)
{
if (pathinfo($file, PATHINFO_EXTENSION) === 'less') {
$code = Process::run("{$this->bin} -", $code, dirname($file), $this->env);
}
return $code;
}
示例4: run
/**
* Forks and run the process.
*
* @param Closure|string|array $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @return integer The exit status code
*/
public function run($callback = null)
{
if (null === $this->commandline) {
$this->commandline = $this->getPhpBinary();
}
parent::run($callback);
}
示例5: testRun
/**
* Tests Process::run
*/
public function testRun()
{
$cmd = new Cmd('echo 1');
$process = new Process();
$process->addCommand($cmd);
$res = $process->run();
$this->assertEquals(0, $res->getCode(), 'echo should work everywhere');
}
示例6: __invoke
/**
* Invoke filter
*
* @param string
* @param \WebLoader\Compiler
* @param string
* @return string
*/
public function __invoke($code, \WebLoader\Compiler $loader, $file = NULL)
{
if (pathinfo($file, PATHINFO_EXTENSION) === 'styl') {
$cmd = $this->bin . ($this->compress ? ' -c' : '');
$code = Process::run($cmd, $code);
}
return $code;
}
示例7: compileCoffee
/**
* @param string
* @param bool|NULL
* @return string
*/
public function compileCoffee($source, $bare = NULL)
{
if (is_null($bare)) {
$bare = $this->bare;
}
$cmd = $this->bin . ' -p -s' . ($bare ? ' -b' : '');
return Process::run($cmd, $source);
}
示例8: copy
/**
* Copies the specified hook to your repos git hooks directory only if it
* doesn't already exist!
* @param string $hook the hook to copy/symlink
* @return void
*/
public function copy($hook)
{
if (false === file_exists(self::GIT_HOOKS_PATH . $hook)) {
// exec('cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' ' . GIT_HOOKS_PATH . $hook);
$copy = new Process('cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' .git/hooks/' . $hook);
$copy->run();
}
}
示例9: detectProcessorNumberByGrep
protected function detectProcessorNumberByGrep()
{
if (Utils::findBin('grep') && file_exists('/proc/cpuinfo')) {
$process = new Process('grep -c ^processor /proc/cpuinfo 2>/dev/null');
$process->run();
$this->processorNumber = intval($process->getOutput());
return $this->processorNumber;
}
return;
}
示例10: __invoke
/**
* Invoke filter
*
* @param string $code
* @param \WebLoader\Compiler $compiler
* @param string $file
* @return string
*/
public function __invoke($code, \WebLoader\Compiler $compiler, $file = NULL)
{
if (pathinfo($file, PATHINFO_EXTENSION) === 'ts') {
$out = substr_replace($file, 'js', -2);
$cmd = sprintf("%s %s --target ES5 --out %s", $this->bin, escapeshellarg($file), escapeshellarg($out));
Process::run($cmd, NULL, NULL, $this->env);
$code = file_get_contents($out);
}
return $code;
}
示例11: run
public function run($callback = null)
{
if (null === $this->getCommandLine()) {
if (false === ($php = $this->executableFinder->find())) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
$this->setCommandLine($php);
}
return parent::run($callback);
}
示例12: __invoke
/**
* Invoke filter
*
* @param string
* @param \WebLoader\Compiler
* @param string
* @return string
*/
public function __invoke($code, \WebLoader\Compiler $loader, $file = NULL)
{
if (pathinfo($file, PATHINFO_EXTENSION) === 'styl') {
$path = $cmd = $this->bin . ($this->compress ? ' -c' : '') . ($this->includeCss ? ' --include-css' : '') . ' -I ' . pathinfo($file, PATHINFO_DIRNAME);
try {
$code = Process::run($cmd, $code);
} catch (\RuntimeException $e) {
throw new \WebLoader\WebLoaderException('Stylus Filter Error', 0, $e);
}
}
return $code;
}
示例13: run
/**
* Execute la requete.
*/
public function run()
{
// On envoie une deuxieme fois l'instance au gestionnaire d'erreurs
// (1e fois = Webos->__construct())
// Important pour ServerCallGroup !
Error::setErrorsWebos($this);
try {
//On essaie d'executer l'action demandee
$this->process->run();
} catch (Exception $e) {
//En cas d'erreur
Error::catchException($e);
}
//On envoie la reponse HTTP
$this->getHTTPResponse()->send();
}
示例14: fork
public function fork(Process $children)
{
if ($this->allocateSHMPerChildren()) {
$children->setSHMSegment(new \Zebra\Ipcs\SHMCache(\uniqid('process_manager;shm_per_children' . $children->getInternalId()), $this->allocateSHMPerChildren));
}
\pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD));
$pid = \pcntl_fork();
// Error
if ($pid == -1) {
throw new RuntimeException('pcntl_fork() returned -1, are you sure you are running the script from CLI?');
} else {
if (!$pid) {
$children->run();
exit;
// redundant, added only for clarity
} else {
$children->setStarted(true);
$this->children[] = $children;
// Store the children's PID
$children->setPid($pid);
\pcntl_sigprocmask(SIG_UNBLOCK, array(SIGCHLD));
}
}
}
示例15: executeCommand
/**
* Executes the given command via shell and returns the complete output as
* a string
*
* @param string $command
*
* @return array(status, stdout, stderr)
*/
protected function executeCommand($command)
{
if (class_exists('Symfony\\Component\\Process\\Process')) {
$process = new \Symfony\Component\Process\Process($command, $this->env);
if ($this->timeout !== false) {
$process->setTimeout($this->timeout);
}
} else {
$process = new Process($command, $this->env);
}
$process->run();
return array($process->getExitCode(), $process->getOutput(), $process->getErrorOutput());
}