public function start() {
		if( $this->isRunning() ) {
			return;
		}

		$script = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR . 'server.php';

		$stdout = tempnam(sys_get_temp_dir(), 'mockserv-stdout-');
		$cmd    = "php -S {$this->host}:{$this->port} " . escapeshellarg($script);

		if( !putenv(self::TMP_ENV . '=' . $this->tmpDir) ) {
			throw new Exceptions\RuntimeException('Unable to put environmental variable');
		}
		$fullCmd = sprintf('%s > %s 2>&1 & echo $!',
			escapeshellcmd($cmd),
			escapeshellarg($stdout)
		);

		InternalServer::incrementRequestCounter($this->tmpDir, 0);

		$this->pid = exec(
			$fullCmd,
			$o,
			$ret
		);

		if( !ctype_digit($this->pid) ) {
			throw new Exceptions\ServerException("Error starting server, received '{$this->pid}', expected int PID");
		}

		sleep(1); // just to make sure it's fully started up, maybe not necessary

		if( !$this->isRunning() ) {
			throw new Exceptions\ServerException("Failed to start server. Is something already running on port {$this->port}?");
		}

		$this->started = true;

		register_shutdown_function(function () {
			if( $this->isRunning() ) {
				$this->stop();
			}
		});
	}
public function start() {
		if( $this->isRunning() ) {
			return;
		}

		$script = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR . 'server.php';

		$stdout = tempnam(sys_get_temp_dir(), 'mockserv-stdout-');
		$cmd    = "php -S {$this->host}:{$this->port} " . escapeshellarg($script);

		if( !putenv(self::TMP_ENV . '=' . $this->tmpDir) ) {
			throw new Exceptions\RuntimeException('Unable to put environmental variable');
		}
		$fullCmd = sprintf('%s > %s 2>&1 & echo $!',
			escapeshellcmd($cmd),
			escapeshellarg($stdout)
		);

		InternalServer::incrementRequestCounter($this->tmpDir, 0);

		$this->pid = exec(
			$fullCmd,
			$o,
			$ret
		);

		if( !ctype_digit($this->pid) ) {
			throw new Exceptions\ServerException("Error starting server, received '{$this->pid}', expected int PID");
		}

		sleep(1); // just to make sure it's fully started up, maybe not necessary

		if( !$this->isRunning() ) {
			throw new Exceptions\ServerException("Failed to start server. Is something already running on port {$this->port}?");
		}

		$this->started = true;

		register_shutdown_function(function () {
			if( $this->isRunning() ) {
				$this->stop();
			}
		});
	}
public function start ( ) { if ( $ this -> isRunning ( ) ) { return ; } $ script = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR . 'server.php' ; $ stdout = tempnam ( sys_get_temp_dir ( ) , 'mockserv-stdout-' ) ; $ cmd = "php -S {$this->host}:{$this->port} " . escapeshellarg ( $ script ) ; if ( ! putenv ( self :: TMP_ENV . '=' . $ this -> tmpDir ) ) { throw new Exceptions \ RuntimeException ( 'Unable to put environmental variable' ) ; } $ fullCmd = sprintf ( '%s > %s 2>&1 & echo $!' , escapeshellcmd ( $ cmd ) , escapeshellarg ( $ stdout ) ) ; InternalServer :: incrementRequestCounter ( $ this -> tmpDir , 0 ) ; $ this -> pid = exec ( $ fullCmd , $ o , $ ret ) ; if ( ! ctype_digit ( $ this -> pid ) ) { throw new Exceptions \ ServerException ( "Error starting server, received '{$this->pid}', expected int PID" ) ; } sleep ( 1 ) ; // just to make sure it's fully started up, maybe not necessary if ( ! $ this -> isRunning ( ) ) { throw new Exceptions \ ServerException ( "Failed to start server. Is something already running on port {$this->port}?" ) ; } $ this -> started = true ; register_shutdown_function ( function ( ) { if ( $ this -> isRunning ( ) ) { $ this -> stop ( ) ; } } ) ; }
Start the Web Server on the selected port and host
Start the Web Server on the selected port and host