start() public méthode

public start ( $state )
 /**
  * Asynchronously start mediainfo operation.
  * Make call to MediaInfoCommandRunner::wait() afterwards to receive output.
  */
 public function start()
 {
     $this->processBuilder->add($this->filePath);
     $this->processAsync = $this->processBuilder->getProcess();
     // just takes advantage of symfony's underlying Process framework
     // process runs in background
     $this->processAsync->start();
 }
Exemple #2
0
 /**
  * add a process
  *
  * @param Process $process
  * @param null|string $name process name
  * @return int
  */
 public function execute(Process $process, $name = null)
 {
     if (!is_null($name)) {
         $process->name($name);
     }
     $process->start();
     return array_push($this->processes, $process);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function start($callback = null)
 {
     if (null === $this->getCommandLine()) {
         if (false === ($php = $this->executableFinder->find())) {
             throw new \RuntimeException('Unable to find the PHP executable.');
         }
         $this->setCommandLine($php);
     }
     parent::start($callback);
 }
Exemple #4
0
 /**
  * start new processes if needed
  *
  * @return int num of job
  */
 public function tick()
 {
     if ($this->countPool() < 1 && $this->countJob()) {
         $job = $this->getJob();
         if ($job) {
             $szal = new Process($this->worker);
             $szal->setLifeTime(4);
             //NOTICE
             $this->pool[] = $szal;
             $szal->start($job);
         }
     }
     return $this->countJob();
 }
 /**
  * start the same number processes and kill the old sub process
  * just like nginx -s reload
  * this method will block until all the old process exit;
  *
  * @param bool $block
  */
 public function reload($block = true)
 {
     $old_process = $this->processes;
     for ($i = 0; $i < $this->max; $i++) {
         $process = new Process($this->runnable);
         $process->start();
         $this->processes[$process->getPid()] = $process;
     }
     foreach ($old_process as $process) {
         $process->shutdown();
         $process->wait($block);
         unset($this->processes[$process->getPid()]);
     }
 }
Exemple #6
0
 /**
  * Starts Budabot instance.
  * Calling this more than once has no effect unless the bot is not running.
  */
 public static function startBudabot()
 {
     if (self::$botProcess) {
         return;
     }
     // delete old DB-file if it exists
     @unlink(ROOT_PATH . '/data/' . self::$vars['DB Name']);
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         $phpExec = realpath(ROOT_PATH . "\\win32\\php.exe") . " -c php-win.ini";
     } else {
         $phpExec = "php";
     }
     // start budabot instance
     $process = new Process();
     $process->setCommand("{$phpExec} -f tests/helpers/test_main.php");
     $path = self::$parameters['budabot_log'];
     if (is_string($path)) {
         $file = fopen($path, 'w');
         $process->setDescriptorspec(array(1 => $file, 2 => $file));
     } else {
         if ($path) {
             $process->setDescriptorspec(array());
         } else {
             $process->setDescriptorspec(array(1 => array('file', 'nul', 'w'), 2 => array('file', 'nul', 'w')));
         }
     }
     $process->setWorkingDir(ROOT_PATH);
     if (!$process->start()) {
         throw new Exception("Failed to start Budabot!");
     }
     // make sure that the bot instance is terminated on exit
     register_shutdown_function(function () use($process) {
         $process->stop();
     });
     self::$botProcess = $process;
 }
Exemple #7
0
 /**
  * fork process with job
  *
  * @return
  */
 public function spawn()
 {
     $worker = $this->ready();
     $ident = $this->getIdent($worker);
     //use Process
     $p = new Process($worker);
     $p->start();
     $pid = $p->getPid();
     if ($pid) {
         $this->childPool[$ident][$pid] = $pid;
     }
     // //@TODO
     // $pid = pcntl_fork();
     // if ($pid == -1) {
     // } elseif ($pid) {
     //     $this->childPool[$ident][$pid] = $pid;
     // } else {
     //     //@TODO
     //     //$this->setOwner($name = 'www');
     //     //$this->setTitle($title);
     //     $this->childPool[$ident] = [];
     //     //$cid = getmypid();
     //     //echo "\ngetmypid={$cid}\n";
     //     // 这个符号表示恢复系统对信号的默认处理
     //     pcntl_signal(SIGTERM, SIG_DFL);
     //     pcntl_signal(SIGCHLD, SIG_DFL);
     //     call_user_func_array($worker, array());
     //     //call_user_func_array($worker);
     //     exit(0);
     // }
 }
 /**
  * start the pool
  */
 public function start()
 {
     $alive_count = $this->aliveCount();
     // create sub process and run
     if ($alive_count < $this->max) {
         $need = $this->max - $alive_count;
         for ($i = 0; $i < $need; $i++) {
             $process = new Process($this->runnable);
             $process->start();
             $this->processes[$process->getPid()] = $process;
         }
     }
 }
    public $counter;
    public function __construct()
    {
        $this->counter = 0;
    }
    public function run()
    {
    }
}
class Process extends Worker
{
    private $text = "";
    public function __construct($text, $object)
    {
        $this->text = $text;
        $this->object = $object;
    }
    public function run()
    {
        while ($this->object->counter < 10) {
            print $this->object->counter++ . " - {$this->text}\n";
            sleep(1);
        }
    }
}
$foo = new Foo();
$a = new Process("A", $foo);
$a->start();
$b = new Process("B", $foo);
$b->start();
 public static function generate_password()
 {
     global $vncpwd;
     Process::start('php', $vncpwd, false);
 }