本文整理汇总了PHP中Symfony\Component\Process\Process类的典型用法代码示例。如果您正苦于以下问题:PHP Process类的具体用法?PHP Process怎么用?PHP Process使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Process类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
# снимаем ограничение времени выполнения скрипта (в safe-mode не работает)
set_time_limit(0);
$container = $this->getContainer();
$logger = $container->get('vidal.digest_logger');
$em = $container->get('doctrine')->getManager();
# рассылаем с помощью EventSendCommand
$command = 'php ' . $container->get('kernel')->getRootDir() . '/console vidal:eventsend ';
$doctors = $em->createQuery('
SELECT e.username
FROM VidalMainBundle:User e
')->getResult();
$emails = array();
foreach ($doctors as $doctor) {
$emails[] = $doctor['username'];
}
// $emails[] = 'tulupov.m@gmail.com';
$emails = array_diff($emails, $logger->getSentEmails());
for ($i = 0, $c = count($emails); $i < $c; $i = $i + 100) {
$emails100 = array_slice($emails, $i, 100);
$emails100 = implode(' ', $emails100);
# формируем команду для рассылки соточки
try {
$processCmd = $command . $emails100;
$process = new Process($processCmd);
$process->run();
} catch (\Exception $e) {
continue;
}
$process = null;
sleep(40);
}
}
示例2: execute
/**
* Execute the command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$process = new Process('vagrant resume', realpath(__DIR__ . '/../'), $_ENV, null, null);
$process->run(function ($type, $line) use($output) {
$output->write($line);
});
}
示例3: download
public function download($in_dir)
{
$repo = $in_dir . '/' . $this->package . ".git";
if (is_dir($repo)) {
return;
}
$cmd = 'git clone --mirror %s %s';
$process = new Process(sprintf($cmd, $this->url, $repo));
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception($process->getErrorOutput());
}
$cmd = 'cd %s && git update-server-info -f';
$process = new Process(sprintf($cmd, $repo));
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception($process->getErrorOutput());
}
$cmd = 'cd %s && git fsck';
$process = new Process(sprintf($cmd, $repo));
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception($process->getErrorOutput());
}
}
示例4: dump_base
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
{
$date_obj = new DateTime();
$filename = sprintf('%s%s_%s.sql', p4string::addEndSlash($input->getArgument('directory')), $base->get_dbname(), $date_obj->format('Y_m_d_H_i_s'));
$command = sprintf('mysqldump %s %s %s %s %s %s --default-character-set=utf8', '--host=' . escapeshellarg($base->get_host()), '--port=' . escapeshellarg($base->get_port()), '--user=' . escapeshellarg($base->get_user()), '--password=' . escapeshellarg($base->get_passwd()), '--databases', escapeshellarg($base->get_dbname()));
if ($input->getOption('gzip')) {
$filename .= '.gz';
$command .= ' | gzip -9';
} elseif ($input->getOption('bzip')) {
$filename .= '.bz2';
$command .= ' | bzip2 -9';
}
$output->write(sprintf('Generating <info>%s</info> ... ', $filename));
$command .= ' > ' . escapeshellarg($filename);
$process = new Process($command);
$process->setTimeout((int) $input->getOption('timeout'));
$process->run();
if (!$process->isSuccessful()) {
$output->writeln('<error>Failed</error>');
return 1;
}
if (file_exists($filename) && filesize($filename) > 0) {
$output->writeln('OK');
return 0;
} else {
$output->writeln('<error>Failed</error>');
return 1;
}
}
示例5: __construct
public function __construct(\Symfony\Component\Process\Process $process)
{
$this->process = $process;
$code = 0;
$message = '';
// Not all of the ansible errors have output in stderr. Therefore, if
// stderr is empty we will use the stdout output instead to get clues
// on what the actual error was.
$error = $process->getErrorOutput();
if (is_null($error)) {
$error = $process->getOutput();
}
// Figure out the specific error that occured
if (false !== strpos($error, 'the playbook') && false !== strpos($error, 'could not be found')) {
$code = self::NOT_FOUND;
$message = self::NOT_FOUND_MSG;
} else {
if (false !== strpos($error, 'Syntax Error while loading YAML script')) {
$code = self::SYNTAX_ERROR;
$message = self::SYNTAX_ERROR_MSG;
} else {
if (false !== strpos($error, 'One or more undefined variables')) {
$code = self::UNDEFINED_VARIABLE;
$message = self::UNDEFINED_VARIABLE_MSG;
} else {
$code = self::GENERAL_ERROR;
$message = self::GENERAL_ERROR_MSG;
}
}
}
parent::__construct($message, $code);
}
示例6: compile
/**
* Compiles the Silex source code into one single Phar file.
*
* @param string $pharFile Name of the output Phar file
*/
public function compile($pharFile = 'silex.phar')
{
if (file_exists($pharFile)) {
unlink($pharFile);
}
$process = new Process('git log --pretty="%h %ci" -n1 HEAD');
if ($process->run() > 0) {
throw new \RuntimeException('The git binary cannot be found.');
}
$this->version = trim($process->getOutput());
$phar = new \Phar($pharFile, 0, 'silex.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Finder();
$finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..')->in(__DIR__ . '/../../vendor/pimple/pimple/lib')->in(__DIR__ . '/../../vendor/symfony/class-loader/Symfony/Component/ClassLoader')->in(__DIR__ . '/../../vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher')->in(__DIR__ . '/../../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation')->in(__DIR__ . '/../../vendor/symfony/http-kernel/Symfony/Component/HttpKernel')->in(__DIR__ . '/../../vendor/symfony/routing/Symfony/Component/Routing')->in(__DIR__ . '/../../vendor/symfony/browser-kit/Symfony/Component/BrowserKit')->in(__DIR__ . '/../../vendor/symfony/css-selector/Symfony/Component/CssSelector')->in(__DIR__ . '/../../vendor/symfony/dom-crawler/Symfony/Component/DomCrawler');
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php'));
// Stubs
$phar->setStub($this->getStub());
$phar->stopBuffering();
// $phar->compressFiles(\Phar::GZ);
unset($phar);
}
示例7: compile
/**
* Compiles composer into a single phar file
*
* @throws \RuntimeException
* @param string $pharFile The full path to the file to create
*/
public function compile($pharFile = 'composer.phar')
{
if (file_exists($pharFile)) {
unlink($pharFile);
}
$process = new Process('git log --pretty="%h" -n1 HEAD');
if ($process->run() != 0) {
throw new \RuntimeException('The git binary cannot be found.');
}
$this->version = trim($process->getOutput());
$phar = new \Phar($pharFile, 0, 'composer.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();
$finder = new Finder();
$finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..');
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$finder = new Finder();
$finder->files()->ignoreVCS(true)->name('*.php')->in(__DIR__ . '/../../vendor/symfony/');
foreach ($finder as $file) {
$this->addFile($phar, $file);
}
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php'));
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php'));
$this->addComposerBin($phar);
// Stubs
$phar->setStub($this->getStub());
$phar->stopBuffering();
// disabled for interoperability with systems without gzip ext
// $phar->compressFiles(\Phar::GZ);
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false);
unset($phar);
}
示例8: uploadFileAction
/**
* @Route("/file-upload", name="uploadFile")
* @Template()
*/
public function uploadFileAction(Request $request)
{
$allow = $request->get('private', false);
/** @var File $file */
$file = $request->files->get('file');
$imageName = uniqid('legofy-online') . '.png';
$command = sprintf('legofy %s/%s %s/../../../web/images/%s', $file->getPath(), $file->getFilename(), __DIR__, $imageName);
$process = new Process($command);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$imagine = new Imagine();
$imageFile = $imagine->open(sprintf('%s/../../../web/images/%s', __DIR__, $imageName));
$box = $imageFile->getSize();
if ($box->getHeight() > $box->getWidth()) {
$imageFile->resize(new Box(400, $box->getHeight() * (400 / $box->getWidth())))->crop(new Point(0, 0), new Box(400, 400));
} else {
$newWidth = $box->getWidth() * (400 / $box->getHeight());
$imageFile->resize(new Box($newWidth, 400))->crop(new Point(($newWidth - 400) / 2, 0), new Box(400, 400));
}
$imageFile->save(sprintf('%s/../../../web/images/thumbnails/%s', __DIR__, $imageName));
$image = new Image();
$image->setPrivate($allow)->setName($imageName)->setCreationDate(new \DateTime());
$em = $this->getDoctrine()->getManager();
$em->persist($image);
$em->flush();
return new JsonResponse(['url' => $this->generateUrl('editImage', ['id' => $image->getId(), 'name' => $image->getName()])]);
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$distribution = $input->getArgument('distribution');
$version = $input->getArgument('version');
$download = $this->downloadProject($distribution, $version);
$process = new Process("tar -xzf {$download['location']} -C /tmp/");
$process->start();
if (substr($version, 0, 3) == '7.x') {
$finder = new Finder();
$process->wait();
// Find all modules dropped in to the distribution.
$finder->files()->name("*.info");
$filename = array();
foreach ($finder->in($download['locationUncompressed']) as $file) {
$filename[] = array('path' => $file->getRealPath(), 'filename' => $file->getFileName());
}
// Create the array for the containing modules.
$return = array();
foreach ($filename as $file) {
$contents = $this->parse_info_file(file_get_contents($file['path']));
$machine_name = substr($file['filename'], 0, strpos($file['filename'], '.'));
$return[$machine_name] = array('name' => $contents['name'], 'machine_name' => substr($file['filename'], 0, strpos($file['filename'], '.')), 'core' => $contents['core'], 'version' => $contents['version'], 'status' => 'Enabled', 'package' => isset($contents['package']) ? $contents['package'] : null);
}
$output->write(json_encode($return));
}
}
示例10: testPhpdocIsInstalled
/**
*@group cmd
*/
public function testPhpdocIsInstalled()
{
$process = new Process('phpdoc --version');
$process->run();
$output = $process->getOutput();
$this->assertContains("phpDocumentor version", $output);
}
示例11: deserialize
/**
* @param string $serialized
*
* @return Process
*/
public function deserialize($serialized)
{
$data = json_decode($serialized, true);
$process = new Process($data['command']);
$process->setTimeout($data['timeout']);
return $process;
}
示例12: run
/**
* @param $command
* @param $projectPath
* @param OutputInterface $output
*/
protected function run($command, $projectPath, OutputInterface $output)
{
$process = new Process($command, $projectPath, array_merge($_SERVER, $_ENV), null, null);
$process->run(function ($type, $line) use($output) {
$output->write($line);
});
}
示例13: runFix
/**
* @param string $path
* @param Event $event
*/
protected static function runFix($path, Event $event)
{
$bin = self::getOption('phpcsfixer-bin', $event);
$failOnError = self::getOption('phpcsfixer-fail-on-error', $event);
$logPrepend = self::getOption('phpcsfixer-log-prepend', $event);
$level = self::getOption('phpcsfixer-level', $event);
$fixers = self::getOption('phpcsfixer-fixers', $event);
$config = self::getOption('phpcsfixer-config', $event);
$dryRun = self::getOption('phpcsfixer-dry-run', $event);
$command = array($bin, 'fix', $path);
if ($level) {
$command[] = '--level=' . $level;
}
if (!empty($fixers) && is_array($fixers)) {
$command[] = '--fixers=' . implode(',', $fixers);
}
if ($config) {
$command[] = '--config=' . $config;
}
if ($dryRun === true) {
$command[] = '--dry-run';
}
if (!$failOnError) {
$command[] = '|| true';
}
$process = new Process(implode(' ', $command), null, null, null, null, []);
$process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
});
}
示例14: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getApplication()->getContainer();
$commandFile = realpath($_SERVER['SCRIPT_FILENAME']);
$currentVersion = "v" . $container->getVersion();
$updateVersion = trim(@file_get_contents('https://raw.githubusercontent.com/kohkimakimoto/altax/master/version'));
if (!$container->isPhar()) {
$output->writeln('<error>You can not update altax. Because altax only supports self-update command on PHAR file version.</error>');
return 1;
}
if (!preg_match('/^v[0-9].[0-9]+.[0-9]+$/', $updateVersion)) {
$output->writeln('<error>You can not update altax. Because the latest version of altax are not available for download.</error>');
return 1;
}
if ($currentVersion === $updateVersion) {
$output->writeln('<info>You are already using altax version <comment>' . $updateVersion . '</comment>.</info>');
return 0;
}
$output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
$tmpDir = "/tmp/" . uniqid("altax.update.");
$process = new Process("mkdir {$tmpDir} && cd {$tmpDir} && curl -L https://raw.githubusercontent.com/kohkimakimoto/altax/master/installer.sh | bash -s local {$updateVersion}");
$process->setTimeout(null);
if ($process->run() !== 0) {
$output->writeln('<error>You can not update altax.');
return 1;
}
$fs = new Filesystem();
$fs->copy($tmpDir . "/altax.phar", $commandFile, true);
$fs->remove($tmpDir);
$output->writeln("Done.");
}
示例15: execute
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output, $retried = false)
{
if ($this->getContainer()->get('foreman.accessor')->ping()) {
$output->writeln('<error>The Foreman Processor server is already running.');
return;
}
if ($input->getOption('daemon')) {
$phpPath = (new PhpExecutableFinder())->find();
$process = new Process($phpPath . ' app/console foreman:processor:start' . ($input->getOption('verbose') ? ' -v' : ''));
$process->setTimeout(0);
$output->writeln('<info>Starting daemon server...');
$process->start();
$accessor = $this->getContainer()->get('foreman.accessor');
$start = time();
$interval = $this->getContainer()->getParameter('foreman.processor')['interval'];
//When we try to ping the server the first time, it almost always fails.
//The server isn't started yet by the time we get here, so we wait.
//Timeout = 3 seconds. Should be enough for all servers.
while (!$accessor->ping() && time() - $start < 3) {
sleep($interval);
}
if ($accessor->ping()) {
$status = $accessor->status();
$output->writeln('<info>The server was started successfully with PID ' . $status['pid'] . '</info>');
} else {
$output->writeln('<error>The server could not be started at this moment.</error>');
$output->writeln('Please check if the server port (' . $this->getContainer()->getParameter('foreman.processor.port') . ') is available.');
$output->writeln('If you have closed the server recently, the connection may not have released. Try again ' . 'in a few seconds.');
}
} else {
$output->writeln('<info>Starting the Foreman Processor...</info>');
$this->getContainer()->get('foreman.processor')->start($output, $input->getOption('verbose'));
}
}