コード例 #1
0
ファイル: PhantomJS.php プロジェクト: mast3rpee/blw
 /**
  * Starts PhantomJS process.
  *
  * @return boolean <code>TRUE</code> on success. <code>FALSE</code> on failure.
  */
 public function phantomStart()
 {
     // Create Command
     $this->_Process = new ShellCommand($this->_Executable, $this->_Config, $this->_Mediator, 'PhantomJS');
     // Custom stdOut / stdErr handling
     $this->_Process->onOutput(function (IEvent $Event) {
         // ##################################################################
         // NOTE:
         // ##################################################################
         // PHP is very anoying as it will block on reads from stdout / stderr
         // pipe. This cannot be stopped with either stream_set_blocking() or
         // stream_set_timeout(). Therefore I place an end of output marker
         // (Ctrl + D) and disable stderr in order to make reads without
         // hanging.
         //
         // Times like these I love nodejs
         // ##################################################################
         // Prevent reading from stderr (hangs)
         unset($Event->Pipes[1]);
         // Check for Ctrl+D
         if (strpos(substr($Event->Data, -3), "") !== false) {
             unset($Event->Pipes[0]);
         }
     });
     // Start Command
     return $this->phantomRestart();
 }