@@ -43,7 +43,7 @@ protected function configure()
4343 {
4444 $ this
4545 ->setDefinition (array (
46- new InputArgument ('address ' , InputArgument::OPTIONAL , 'Address:port ' , 'localhost :8000 ' ),
46+ new InputArgument ('address ' , InputArgument::OPTIONAL , 'Address:port ' , '127.0.0.1 :8000 ' ),
4747 new InputOption ('docroot ' , 'd ' , InputOption::VALUE_REQUIRED , 'Document root ' , 'web/ ' ),
4848 new InputOption ('router ' , 'r ' , InputOption::VALUE_REQUIRED , 'Path to custom router script ' ),
4949 ))
@@ -84,20 +84,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484 $ output ->writeln ('<error>Running PHP built-in server in production environment is NOT recommended!</error> ' );
8585 }
8686
87- $ router = $ input ->getOption ('router ' ) ?: $ this
88- ->getContainer ()
89- ->get ('kernel ' )
90- ->locateResource (sprintf ('@FrameworkBundle/Resources/config/router_%s.php ' , $ env ))
91- ;
92-
9387 $ output ->writeln (sprintf ("Server running on <info>%s</info> \n" , $ input ->getArgument ('address ' )));
9488
9589 if (defined ('HHVM_VERSION ' )) {
96- $ this ->executeWithHHVM ($ input , $ output , $ env );
97- return ;
90+ $ builder = $ this ->createHhvmProcessBuilder ($ input , $ output , $ env );
91+ } else {
92+ $ builder = $ this ->createPhpProcessBuilder ($ input , $ output , $ env );
9893 }
9994
100- $ builder = new ProcessBuilder (array (PHP_BINARY , '-S ' , $ input ->getArgument ('address ' ), $ router ));
10195 $ builder ->setWorkingDirectory ($ input ->getOption ('docroot ' ));
10296 $ builder ->setTimeout (null );
10397 $ builder ->getProcess ()->run (function ($ type , $ buffer ) use ($ output ) {
@@ -107,12 +101,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
107101 });
108102 }
109103
110- protected function executeWithHHVM (InputInterface $ input , OutputInterface $ output , $ env )
104+ private function createPhpProcessBuilder (InputInterface $ input , OutputInterface $ output , $ env )
105+ {
106+ $ router = $ input ->getOption ('router ' ) ?: $ this
107+ ->getContainer ()
108+ ->get ('kernel ' )
109+ ->locateResource (sprintf ('@FrameworkBundle/Resources/config/router_%s.php ' , $ env ))
110+ ;
111+
112+ return new ProcessBuilder (array (PHP_BINARY , '-S ' , $ input ->getArgument ('address ' ), $ router ));
113+ }
114+
115+ private function createHhvmProcessBuilder (InputInterface $ input , OutputInterface $ output , $ env )
111116 {
112117 list ($ ip , $ port ) = explode (': ' , $ input ->getArgument ('address ' ));
113- $ output -> writeln ( sprintf ( " Server(with HHVM) running on <info> $ ip : $ port </info> \n" , $ ip , $ port ));
118+
114119 $ docroot = realpath ($ input ->getOption ('docroot ' ));
115- $ bootstrap = ( 'prod ' === $ env ? 'app.php ' : 'app_dev.php ' ) ;
120+ $ bootstrap = 'prod ' === $ env ? 'app.php ' : 'app_dev.php ' ;
116121 $ config = <<<EOF
117122Server {
118123 IP = $ ip
@@ -123,9 +128,9 @@ protected function executeWithHHVM(InputInterface $input, OutputInterface $outpu
123128}
124129
125130VirtualHost {
126- * {
127- Pattern = .*
128- RewriteRules {
131+ * {
132+ Pattern = .*
133+ RewriteRules {
129134 * {
130135 pattern = .?
131136
@@ -135,8 +140,8 @@ protected function executeWithHHVM(InputInterface $input, OutputInterface $outpu
135140 # append the original query string
136141 qsa = true
137142 }
138- }
139- }
143+ }
144+ }
140145}
141146
142147StaticFile {
@@ -155,16 +160,10 @@ protected function executeWithHHVM(InputInterface $input, OutputInterface $outpu
155160 }
156161}
157162EOF ;
158- $ tmpfile = $ this ->getContainer ()->get ('kernel ' )->getCacheDir ().DIRECTORY_SEPARATOR .'hhvm-server- ' .md5 ($ config ).'.hdf ' ;
159- file_put_contents ($ tmpfile , $ config );
160- $ builder = new ProcessBuilder (array (PHP_BINARY , '-ms ' , "-c $ tmpfile " ));
161- $ builder ->setWorkingDirectory ($ docroot );
162- $ builder ->setTimeout (null );
163- $ builder ->getProcess ()->run (function ($ type , $ buffer ) use ($ output ) {
164- if (OutputInterface::VERBOSITY_VERBOSE <= $ output ->getVerbosity ()) {
165- $ output ->write ($ buffer );
166- }
167- });
168- }
169163
164+ $ configFile = $ this ->getContainer ()->get ('kernel ' )->getCacheDir ().'/hhvm-server- ' .md5 ($ config ).'.hdf ' ;
165+ file_put_contents ($ configFile , $ config );
166+
167+ return new ProcessBuilder (array (PHP_BINARY , '--mode ' , 'server ' , '--config ' , $ configFile ));
168+ }
170169}
0 commit comments