isStarted() public method

Checks if the process has been started with no regard to the current state.
public isStarted ( ) : boolean
return boolean true if status is ready, false otherwise
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $channels = [];
     $maxChannels = $input->getArgument('CPUs');
     $exampleArray = $this->getExampleArray();
     $output->writeln('<fg=green>Start example process</>');
     while (count($exampleArray) > 0 || count($channels) > 0) {
         foreach ($channels as $key => $channel) {
             if ($channel instanceof Process && $channel->isTerminated()) {
                 unset($channels[$key]);
             }
         }
         if (count($channels) >= $maxChannels) {
             continue;
         }
         if (!($item = array_pop($exampleArray))) {
             continue;
         }
         $process = new Process(sprintf('php index.php example:sub-process %s', $item), __DIR__ . '/../../../');
         $process->start();
         if (!$process->isStarted()) {
             throw new \Exception($process->getErrorOutput());
         }
         $channels[] = $process;
     }
     $output->writeln('<bg=green;fg=black>Done.</>');
 }
示例#2
0
 /**
  * @return bool
  */
 private function handleProcess(Process $process)
 {
     if ($process->isStarted()) {
         if ($process->isTerminated()) {
             $this->running--;
             return true;
         }
         return false;
     }
     // Only start a new process if we haven't reached the limit yet.
     if ($this->running < $this->config->getProcessAsyncLimit()) {
         $process->start();
         $this->running++;
     }
     return false;
 }
示例#3
0
文件: Serve.php 项目: narno/phpoole
 public function processCommand()
 {
     $this->watch = $this->getRoute()->getMatchedParam('watch', false);
     $this->fileSystem = new Filesystem();
     $this->setUpServer();
     $command = sprintf('php -S %s:%d -t %s %s', 'localhost', '8000', $this->getPath() . '/' . $this->getPHPoole()->getOption('output.dir'), sprintf('%s/.phpoole/router.php', $this->getPath()));
     $this->wlAnnonce(sprintf('Starting server (http://%s:%d)...', 'localhost', '8000'));
     $process = new Process($command);
     if (!$process->isStarted()) {
         // write changes cache
         if ($this->watch) {
             $finder = new Finder();
             $finder->files()->name('*.md')->name('*.html')->in([$this->getPath() . '/' . $this->getPHPoole()->getOption('content.dir'), $this->getPath() . '/' . $this->getPHPoole()->getOption('layouts.dir')]);
             if (is_dir($this->getPath() . '/' . $this->getPHPoole()->getOption('themes.dir'))) {
                 $finder->in($this->getPath() . '/' . $this->getPHPoole()->getOption('themes.dir'));
             }
             $resourceCache = new ResourceCacheMemory();
             $resourceWatcher = new ResourceWatcher($resourceCache);
             $resourceWatcher->setFinder($finder);
             $this->fileSystem->dumpFile($this->getPath() . '/.phpoole/watch.flag', '');
         }
         // start server
         try {
             $process->start();
             Plateform::openBrowser('http://localhost:8000');
             while ($process->isRunning()) {
                 // watch changes?
                 if ($this->watch) {
                     $resourceWatcher->findChanges();
                     if ($resourceWatcher->hasChanges()) {
                         $this->fileSystem->dumpFile($this->getPath() . '/.phpoole/changes.flag', '');
                         // re-generate
                         $this->wlAlert('Changes detected!');
                         $callable = new Build();
                         call_user_func($callable, $this->getRoute(), $this->getConsole());
                     }
                 }
                 usleep(1000000);
                 // 1 s
             }
         } catch (ProcessFailedException $e) {
             $this->tearDownServer();
             echo $e->getMessage();
             exit(2);
         }
     }
 }
示例#4
0
 /**
  * Execute the process (or the optional process) and handle its response ouput.
  *
  * @param Process $process
  * @return bool
  */
 public function execute(Process $process = null)
 {
     $this->process = $process ?: $this->getProcess();
     try {
         if (!$this->process->isStarted()) {
             $this->process->run();
         }
         if ($this->process->isSuccessful()) {
             $output = explode(static::BATCH_BREAK, $this->process->getOutput());
             array_shift($output);
             foreach ($this->batches as $index => $batch) {
                 $response = $output[$index];
                 $response = preg_replace('(^\\s+|\\s+$)', '', $response);
                 $batch->setProcessResponse($response);
             }
             return true;
         }
     } catch (ProcessExceptionInterface $e) {
         //  need to handle exceptions here.
         //  make sure the catch falls through to the return false.
     }
     return false;
 }
 public function isStarted()
 {
     return $this->process->isStarted() && $this->portIsAcceptingConnections();
 }
示例#6
0
 /**
  * @param $address
  * @param $environment
  */
 protected function startServer()
 {
     $publicDir = $this->getApplication()->getWorkingPath() . DS . 'public';
     $shellCommand = $this->getBaseCommand();
     $process = new Process($shellCommand, $publicDir);
     if ($this->getInput()->getOption('background')) {
         $process->disableOutput();
         $process->start();
         $processId = $this->getProcessId();
         $this->getApplication()->getConfig()->setOption('server', ['pid' => $processId, 'address' => $address = 'http://' . $this->getAddress()]);
         $this->getOutput()->writeln($this->info('Server has been started at ' . $address));
     } else {
         while ($process instanceof Process) {
             if (!$process->isStarted()) {
                 $process->start();
                 continue;
             }
             echo $process->getIncrementalOutput();
             echo $process->getIncrementalErrorOutput();
             if (!$process->isRunning() || $process->isTerminated()) {
                 $process = false;
                 $this->getOutput()->writeln("");
                 $this->getOutput()->writeln($this->info('Server has been stopped.'));
             }
             sleep(1);
         }
     }
 }