Esempio n. 1
0
 /**
  * Run cron(s) in multiple domains
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $type = $request->getParam('type');
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException(sprintf('%s can only be used from a console.', __METHOD__));
     }
     $phpSelf = realpath(static::PHP_SELF);
     if (empty($phpSelf) || !is_file($phpSelf)) {
         throw new \RuntimeException(sprintf('%s: php not found at "%s" (in "%s").', __METHOD__, static::PHP_SELF, getcwd()));
     }
     $result = 'Running ' . $type . ' cron(s) ...' . PHP_EOL . PHP_EOL;
     foreach ($this->mimicSiteInfos() as $siteInfo) {
         $domain = $siteInfo->getDomain();
         $process = new Process(array('command' => 'php', 'arguments' => array($phpSelf, 'cron', $domain, $type), 'environmentVariables' => array('GRIDGUYZ_HOST' => $domain, 'HTTP_HOST' => $domain)));
         $result .= 'Calling process ...' . PHP_EOL . $process->getRunCommand() . PHP_EOL;
         $output = tempnam('./data/', $domain);
         $descr = array(Process::TYPE_FILE, $output, Process::MODE_APPEND);
         file_put_contents($output, '');
         $process->open(array(Process::STREAM_STDOUT => $descr, Process::STREAM_STDERR => $descr));
         $return = $process->close();
         $messages = rtrim(file_get_contents($output), PHP_EOL);
         unlink($output);
         if ($messages) {
             $result .= static::PADDING . preg_replace('/[' . PHP_EOL . ']+/', '$0' . static::PADDING, $messages) . PHP_EOL;
         }
         $result .= sprintf('Process returned with #%d: %s' . PHP_EOL . PHP_EOL, $return, $return ? 'error!' : 'success.');
     }
     $result .= 'Done.' . PHP_EOL;
     return $result;
 }
Esempio n. 2
0
 /**
  * Test run command
  */
 public function testRunCommand()
 {
     $process = new Process(array('command' => 'test$command', 'arguments' => array('arg 1', 'arg/2', 'arg$3')));
     $this->assertEquals(escapeshellcmd('test$command') . ' ' . escapeshellarg('arg 1') . ' ' . escapeshellarg('arg/2') . ' ' . escapeshellarg('arg$3'), $process->getRunCommand());
     $emptyProcess = new Process();
     $this->assertNull($emptyProcess->getRunCommand());
 }