作者:narog
项目:queue-manage
/**
* 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);
}
作者:ibonell
项目:DrupalConsol
/**
* {@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());
}
}
作者:romainneutro
项目:Phraseane
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);
});
}
作者:netresearc
项目:kit
/**
* 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);
}
作者:mnic
项目:DrupalConsol
/**
* {@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());
}
}
作者:kdyb
项目:seleniu
/**
* @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();
}
作者:narog
项目:queue-manage
/**
* 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();
}
作者:kormi
项目:composer-plugi
/**
* 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;
}
}
作者:luisbrit
项目:Phraseane
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']);
});
}
作者:totte
项目:am
/**
* @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);
}
作者:dpk12
项目:JobQueu
/**
* Constructor.
*
* @param string $environment
* @param $consoleDir
*/
public function __construct($consoleDir, $environment)
{
$this->consoleDir = $consoleDir;
$this->environment = $environment;
$finder = new PhpExecutableFinder();
$this->phpExecutable = $finder->find();
}
作者:webmozar
项目:consol
protected function setUp()
{
$finder = new PhpExecutableFinder();
$this->php = escapeshellcmd($finder->find());
$this->launcher = new ProcessLauncher();
// Speed up the tests
$this->launcher->setCheckInterval(0.01);
}
作者:ashutosh-srija
项目:findit_akene
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;
}
作者:edwardricard
项目:zensk
/**
* 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);
}
作者:proyecto40
项目:UtilBundl
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;
}
作者:gjb204
项目:moodle-plugin-c
/**
* @param string $script Passed to php binary
* @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 inherit
* @param int|float|null $timeout The timeout in seconds or null to disable
*/
public function __construct($script, $cwd = null, array $env = null, $timeout = null)
{
$phpFinder = new PhpExecutableFinder();
// By telling PHP to log errors without having a log file, PHP will write
// errors to STDERR in a specific format (each line is prefixed with PHP).
$commandline = sprintf('%s -d log_errors=1 -d error_log=NULL %s', $phpFinder->find(), $script);
parent::__construct($commandline, $cwd, $env, null, $timeout);
}
作者:startup
项目:platform-
/**
* @see \Symfony\Component\Process\PhpExecutableFinder::find
*/
public function find($includeArgs = true)
{
$php = getenv('ORO_PHP_PATH');
if ($php && is_executable($php)) {
return $php;
}
return $this->finder->find($includeArgs);
}
作者:luisbrit
项目:Phraseane
public function testCreateWithCustomBinary()
{
$finder = new PhpExecutableFinder();
$php = $finder->find();
$driver = ComposerDriver::create(['composer.binaries' => $php]);
$this->assertInstanceOf('Alchemy\\Phrasea\\Command\\Developer\\Utils\\ComposerDriver', $driver);
$this->assertEquals($php, $driver->getProcessBuilderFactory()->getBinary());
}
作者:eriwi
项目:Symfony2Extensio
/**
* Prepares test folders in the temporary directory.
*
* @BeforeScenario
*/
public function prepareProcess()
{
$phpFinder = new PhpExecutableFinder();
if (false === ($php = $phpFinder->find())) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
$this->phpBin = $php;
$this->process = new Process(null);
}
作者:niyomj
项目:laravel_redi
/**
* tests find() with the env var PHP_PATH.
*/
public function testFindArguments()
{
$f = new PhpExecutableFinder();
if (defined('HHVM_VERSION')) {
$this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
} else {
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
}
}