本文整理汇总了PHP中Symfony\Component\Process\PhpExecutableFinder类的典型用法代码示例。如果您正苦于以下问题:PHP PhpExecutableFinder类的具体用法?PHP PhpExecutableFinder怎么用?PHP PhpExecutableFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhpExecutableFinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
$address = $this->validatePort($input->getArgument('address'));
$finder = new PhpExecutableFinder();
if (false === ($binary = $finder->find())) {
$io->error($this->trans('commands.server.errors.binary'));
return;
}
$router = $this->getRouterPath();
$cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router);
if ($learning) {
$io->commentBlock($cli);
}
$io->success(sprintf($this->trans('commands.server.messages.executing'), $binary));
$processBuilder = new ProcessBuilder(explode(' ', $cli));
$process = $processBuilder->getProcess();
$process->setWorkingDirectory($this->appRoot);
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
$process->setTty('true');
} else {
$process->setTimeout(null);
}
$process->run();
if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
}
}
示例3: register
public function register(Application $app)
{
$app['task-manager.logger'] = $app->share(function (Application $app) {
$logger = new $app['monolog.logger.class']('task-manager logger');
$logger->pushHandler(new NullHandler());
return $logger;
});
$app['task-manager'] = $app->share(function (Application $app) {
$options = $app['task-manager.listener.options'];
$manager = TaskManager::create($app['dispatcher'], $app['task-manager.logger'], $app['task-manager.task-list'], ['listener_protocol' => $options['protocol'], 'listener_host' => $options['host'], 'listener_port' => $options['port'], 'tick_period' => 1]);
$manager->addSubscriber($app['ws.task-manager.broadcaster']);
return $manager;
});
$app['task-manager.logger.configuration'] = $app->share(function (Application $app) {
$conf = array_replace(['enabled' => true, 'level' => 'INFO', 'max-files' => 10], $app['conf']->get(['main', 'task-manager', 'logger'], []));
$conf['level'] = defined('Monolog\\Logger::' . $conf['level']) ? constant('Monolog\\Logger::' . $conf['level']) : Logger::INFO;
return $conf;
});
$app['task-manager.task-list'] = $app->share(function (Application $app) {
$conf = $app['conf']->get(['registry', 'executables', 'php-conf-path']);
$finder = new PhpExecutableFinder();
$php = $finder->find();
return new TaskList($app['EM']->getRepository('Phraseanet:Task'), $app['root.path'], $php, $conf);
});
}
示例4: execute
/**
* Actually execute this task
*
* @return \Phar
*/
public function execute()
{
$to = $this->get('to');
if (file_exists($to)) {
$this->console->getFilesystem()->remove($to);
}
$executableFinder = new PhpExecutableFinder();
$php = $executableFinder->find();
$php .= ' -d phar.readonly=0';
$code = "<?php\n";
foreach (array('to', 'from', 'filter', 'cliStub', 'webStub', 'alias', 'metadata') as $var) {
$value = $this->get($var);
$code .= '$' . $var . " = unserialize('" . serialize($value) . "');\n";
}
$code .= '
$phar = new \\Phar($to);
$phar->buildFromDirectory($from, $filter);
if ($cliStub || $webStub) {
$phar->setStub($phar->createDefaultStub($cliStub, $webStub));
}
if ($alias) {
$phar->setAlias($alias);
}
if ($metadata) {
$phar->setMetadata($metadata);
}
?>';
$process = $this->console->createProcess($php);
$process->setInput($code);
$process->run();
return new \Phar($to);
}
示例5: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
$address = $input->getArgument('address');
if (false === strpos($address, ':')) {
$address = sprintf('%s:8088', $address);
}
$finder = new PhpExecutableFinder();
if (false === ($binary = $finder->find())) {
$io->error($this->trans('commands.server.errors.binary'));
return;
}
$router = $this->getRouterPath();
$cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router);
if ($learning) {
$io->commentBlock($cli);
}
$io->success(sprintf($this->trans('commands.server.messages.executing'), $binary));
$processBuilder = new ProcessBuilder(explode(' ', $cli));
$process = $processBuilder->getProcess();
$process->setWorkingDirectory($this->get('site')->getRoot());
$process->setTty('true');
$process->run();
if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
}
}
示例6: start
/**
* @param string $router
* @param array $env
* @return UrlScript
* @throws \RuntimeException
*/
public function start($router, $env = array())
{
$this->slaughter();
static $port;
if ($port === NULL) {
do {
$port = rand(8000, 10000);
if (isset($lock)) {
@fclose($lock);
}
$lock = fopen(dirname(TEMP_DIR) . '/http-server-' . $port . '.lock', 'w');
} while (!flock($lock, LOCK_EX | LOCK_NB, $wouldBlock) || $wouldBlock);
}
$ini = NULL;
if (($pid = getmypid()) && ($myprocess = `ps -ww -fp {$pid}`)) {
$fullArgs = preg_split('~[ \\t]+~', explode("\n", $myprocess)[1], 8)[7];
if (preg_match('~\\s\\-c\\s(?P<ini>[^ \\t]+)\\s~i', $fullArgs, $m)) {
$ini = '-c ' . $m['ini'] . ' -n';
}
}
$executable = new PhpExecutableFinder();
$cmd = sprintf('%s %s -d register_argc_argv=on -t %s -S %s:%d %s', escapeshellcmd($executable->find()), $ini, escapeshellarg(dirname($router)), $ip = '127.0.0.1', $port, escapeshellarg($router));
if (!is_resource($this->process = proc_open($cmd, self::$spec, $this->pipes, dirname($router), $env))) {
throw new HttpServerException("Could not execute: `{$cmd}`");
}
sleep(1);
// give him some time to boot up
$status = proc_get_status($this->process);
if (!$status['running']) {
throw new HttpServerException("Failed to start php server: " . stream_get_contents($this->pipes[2]));
}
$this->url = new UrlScript('http://' . $ip . ':' . $port);
return $this->getUrl();
}
示例7: __construct
/**
* Class constructor
*
* @param TraceableEventDispatcher $dispatcher
* @param AntiDogPileMemcache $memcache
*/
public function __construct(TraceableEventDispatcher $dispatcher, AntiDogPileMemcache $memcache)
{
$this->eventDispatcher = $dispatcher;
$this->memcache = $memcache;
$phpFinder = new PhpExecutableFinder();
$this->phpPath = $phpFinder->find();
}
示例8: __construct
/**
* Creates a new runner.
*
* @param string|null $binDir The path to Composer's "bin-dir".
*/
public function __construct($binDir = null)
{
$phpFinder = new PhpExecutableFinder();
if (!($php = $phpFinder->find())) {
throw new RuntimeException('The "php" command could not be found.');
}
$puliFinder = new ExecutableFinder();
// Search:
// 1. in the current working directory
// 2. in Composer's "bin-dir"
// 3. in the system path
$searchPath = array_merge(array(getcwd()), (array) $binDir);
// Search "puli.phar" in the PATH and the current directory
if (!($puli = $puliFinder->find('puli.phar', null, $searchPath))) {
// Search "puli" in the PATH and Composer's "bin-dir"
if (!($puli = $puliFinder->find('puli', null, $searchPath))) {
throw new RuntimeException('The "puli"/"puli.phar" command could not be found.');
}
}
if (Path::hasExtension($puli, '.bat', true)) {
$this->puli = $puli;
} else {
$this->puli = $php . ' ' . $puli;
}
}
示例9: register
public function register(Application $app)
{
$app['plugins.import-strategy'] = $app->share(function (Application $app) {
return new ImportStrategy();
});
$app['plugins.autoloader-generator'] = $app->share(function (Application $app) {
return new AutoloaderGenerator($app['plugin.path']);
});
$app['plugins.assets-manager'] = $app->share(function (Application $app) {
return new AssetsManager($app['filesystem'], $app['plugin.path'], $app['root.path']);
});
$app['plugins.composer-installer'] = $app->share(function (Application $app) {
$phpBinary = $app['conf']->get(['main', 'binaries', 'php_binary'], null);
if (!is_executable($phpBinary)) {
$finder = new PhpExecutableFinder();
$phpBinary = $finder->find();
}
return new ComposerInstaller($app['composer-setup'], $app['plugin.path'], $phpBinary);
});
$app['plugins.explorer'] = $app->share(function (Application $app) {
return new PluginsExplorer($app['plugin.path']);
});
$app['plugins.importer'] = $app->share(function (Application $app) {
return new Importer($app['plugins.import-strategy'], ['plugins.importer.folder-importer' => $app['plugins.importer.folder-importer']]);
});
$app['plugins.importer.folder-importer'] = $app->share(function (Application $app) {
return new FolderImporter($app['filesystem']);
});
}
示例10: createHostname
/**
* @param string $hostname The hostname to register
*/
public function createHostname($hostname)
{
$content = file_get_contents($this->file);
$lines = explode("\n", $content);
$matchHostLine = $this->findLine($lines, function ($ip, $hostnames) use($hostname) {
return in_array($hostname, $hostnames);
});
if ($matchHostLine) {
return;
}
$f = new PhpExecutableFinder();
$php = $f->find();
if (!$php) {
throw new \RuntimeException("Failed to determine PHP interpreter");
}
$scriptFile = tempnam(sys_get_temp_dir(), 'fix-hosts-php-');
file_put_contents($scriptFile, "<?php\n" . $this->createScript($content, $lines, $hostname));
if ($this->isSudo()) {
echo "Register host \"{$hostname}\" ({$this->ip}) in \"{$this->file}\" via helper \"{$scriptFile}\".\n";
passthru("sudo " . escapeshellarg($php) . " " . escapeshellarg($scriptFile), $return);
} else {
passthru(escapeshellcmd($php) . " " . escapeshellarg($scriptFile), $return);
}
if ($return) {
throw new \RuntimeException("Failed to update hosts file ({$this->file}) with ({$this->ip} {$hostname}) [{$scriptFile}]");
}
unlink($scriptFile);
}
示例11: __construct
/**
* Constructor.
*
* @param string $environment
* @param $consoleDir
*/
public function __construct($consoleDir, $environment)
{
$this->consoleDir = $consoleDir;
$this->environment = $environment;
$finder = new PhpExecutableFinder();
$this->phpExecutable = $finder->find();
}
示例12: setUp
protected function setUp()
{
$finder = new PhpExecutableFinder();
$this->php = escapeshellcmd($finder->find());
$this->launcher = new ProcessLauncher();
// Speed up the tests
$this->launcher->setCheckInterval(0.01);
}
示例13: getPhp
private function getPhp()
{
$phpFinder = new PhpExecutableFinder();
if (!($phpPath = $phpFinder->find())) {
throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
}
return $phpPath;
}
示例14: __construct
/**
* Constructor.
*
* @param string $script The PHP script to run (as a string)
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
* @param int $timeout The timeout in seconds
* @param array $options An array of options for proc_open
*/
public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = array())
{
$executableFinder = new PhpExecutableFinder();
if (false === ($php = $executableFinder->find())) {
$php = null;
}
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
}
示例15: getPhp
protected static function getPhp($includeArgs = true)
{
$phpFinder = new PhpExecutableFinder();
if (!($phpPath = $phpFinder->find($includeArgs))) {
throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
}
return $phpPath;
}