@@ -43,7 +43,7 @@ protected function configure()
43
43
{
44
44
$ this
45
45
->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 ' ),
47
47
new InputOption ('docroot ' , 'd ' , InputOption::VALUE_REQUIRED , 'Document root ' , 'web/ ' ),
48
48
new InputOption ('router ' , 'r ' , InputOption::VALUE_REQUIRED , 'Path to custom router script ' ),
49
49
))
@@ -84,20 +84,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
84
84
$ output ->writeln ('<error>Running PHP built-in server in production environment is NOT recommended!</error> ' );
85
85
}
86
86
87
- $ router = $ input ->getOption ('router ' ) ?: $ this
88
- ->getContainer ()
89
- ->get ('kernel ' )
90
- ->locateResource (sprintf ('@FrameworkBundle/Resources/config/router_%s.php ' , $ env ))
91
- ;
92
-
93
87
$ output ->writeln (sprintf ("Server running on <info>%s</info> \n" , $ input ->getArgument ('address ' )));
94
88
95
89
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 );
98
93
}
99
94
100
- $ builder = new ProcessBuilder (array (PHP_BINARY , '-S ' , $ input ->getArgument ('address ' ), $ router ));
101
95
$ builder ->setWorkingDirectory ($ input ->getOption ('docroot ' ));
102
96
$ builder ->setTimeout (null );
103
97
$ builder ->getProcess ()->run (function ($ type , $ buffer ) use ($ output ) {
@@ -107,12 +101,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
107
101
});
108
102
}
109
103
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 )
111
116
{
112
117
list ($ ip , $ port ) = explode (': ' , $ input ->getArgument ('address ' ));
113
- $ output -> writeln ( sprintf ( " Server(with HHVM) running on <info> $ ip : $ port </info> \n" , $ ip , $ port ));
118
+
114
119
$ docroot = realpath ($ input ->getOption ('docroot ' ));
115
- $ bootstrap = ( 'prod ' === $ env ? 'app.php ' : 'app_dev.php ' ) ;
120
+ $ bootstrap = 'prod ' === $ env ? 'app.php ' : 'app_dev.php ' ;
116
121
$ config = <<<EOF
117
122
Server {
118
123
IP = $ ip
@@ -123,9 +128,9 @@ protected function executeWithHHVM(InputInterface $input, OutputInterface $outpu
123
128
}
124
129
125
130
VirtualHost {
126
- * {
127
- Pattern = .*
128
- RewriteRules {
131
+ * {
132
+ Pattern = .*
133
+ RewriteRules {
129
134
* {
130
135
pattern = .?
131
136
@@ -135,8 +140,8 @@ protected function executeWithHHVM(InputInterface $input, OutputInterface $outpu
135
140
# append the original query string
136
141
qsa = true
137
142
}
138
- }
139
- }
143
+ }
144
+ }
140
145
}
141
146
142
147
StaticFile {
@@ -155,16 +160,10 @@ protected function executeWithHHVM(InputInterface $input, OutputInterface $outpu
155
160
}
156
161
}
157
162
EOF ;
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
- }
169
163
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
+ }
170
169
}
0 commit comments