/** * Builds the full command to execute and stores it in $command. * * @return void * @uses $command */ protected function buildCommand() { if ($this->command === null && $this->commandline->getExecutable() === null) { throw new BuildException('ExecTask: Please provide "command" OR "executable"'); } else { if ($this->command === null) { $this->realCommand = Commandline::toString($this->commandline->getCommandline(), $this->escape); } else { if ($this->commandline->getExecutable() === null) { $this->realCommand = $this->command; //we need to escape the command only if it's specified directly // commandline takes care of "executable" already if ($this->escape == true) { $this->realCommand = escapeshellcmd($this->realCommand); } } else { throw new BuildException('ExecTask: Either use "command" OR "executable"'); } } } if ($this->error !== null) { $this->realCommand .= ' 2> ' . escapeshellarg($this->error->getPath()); $this->log("Writing error output to: " . $this->error->getPath(), $this->logLevel); } if ($this->output !== null) { $this->realCommand .= ' 1> ' . escapeshellarg($this->output->getPath()); $this->log("Writing standard output to: " . $this->output->getPath(), $this->logLevel); } elseif ($this->spawn) { $this->realCommand .= ' 1>/dev/null'; $this->log("Sending output to /dev/null", $this->logLevel); } // If neither output nor error are being written to file // then we'll redirect error to stdout so that we can dump // it to screen below. if ($this->output === null && $this->error === null && $this->passthru === false) { $this->realCommand .= ' 2>&1'; } // we ignore the spawn boolean for windows if ($this->spawn) { $this->realCommand .= ' &'; } }
/** * Starts the web server and runs the encapsulated tasks. */ public function main() { $this->prepare(); $cmd = Commandline::toString($this->commandline->getCommandline(), true); $streams = [["file", "/dev/null", "r"], ["file", "/dev/null", "w"], ["file", "/dev/null", "w"]]; $handle = proc_open($cmd, $streams, $pipes); if (!is_resource($handle)) { throw new BuildException(get_class($this) . ' could not start web server.'); } else { $this->log(sprintf("Started web server, listening on http://%s:%d", $this->address, $this->port), Project::MSG_INFO); $msg = isset($this->router) ? sprintf("with %s as docroot and %s as router", $this->docroot, $this->router) : sprintf("with %s as docroot", $this->docroot); $this->log($msg, Project::MSG_VERBOSE); } try { foreach ($this->tasks as $task) { $task->perform(); } } finally { // Terminate server with SIGINT proc_terminate($handle, 2); $this->log("Stopped web server", Project::MSG_INFO); } }