-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add HHVM support for built-in web server #10017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,11 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
$output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address'))); | ||
|
||
if (defined('HHVM_VERSION')) { | ||
$this->executeWithHHVM($input, $output, $env); | ||
return; | ||
} | ||
|
||
$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router)); | ||
$builder->setWorkingDirectory($input->getOption('docroot')); | ||
$builder->setTimeout(null); | ||
|
@@ -101,4 +106,65 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
}); | ||
} | ||
|
||
protected function executeWithHHVM(InputInterface $input, OutputInterface $output, $env) | ||
{ | ||
list($ip, $port) = explode(':', $input->getArgument('address')); | ||
$output->writeln(sprintf("Server(with HHVM) running on <info>$ip:$port</info>\n", $ip, $port)); | ||
$docroot = realpath($input->getOption('docroot')); | ||
$bootstrap = ('prod' === $env ? 'app.php' : 'app_dev.php'); | ||
$config = <<<EOF | ||
Server { | ||
IP = $ip | ||
Port = $port | ||
SourceRoot = $docroot | ||
RequestTimeoutSeconds = -1 | ||
RequestMemoryMaxBytes = -1 | ||
} | ||
|
||
VirtualHost { | ||
* { | ||
Pattern = .* | ||
RewriteRules { | ||
* { | ||
pattern = .? | ||
|
||
# app bootstrap | ||
to = $bootstrap | ||
|
||
# append the original query string | ||
qsa = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
StaticFile { | ||
Extensions { | ||
css = text/css | ||
gif = image/gif | ||
html = text/html | ||
jpe = image/jpeg | ||
jpeg = image/jpeg | ||
jpg = image/jpeg | ||
png = image/png | ||
tif = image/tiff | ||
tiff = image/tiff | ||
txt = text/plain | ||
php = text/plain | ||
} | ||
} | ||
EOF; | ||
$tmpfile = $this->getContainer()->get('kernel')->getCacheDir().DIRECTORY_SEPARATOR.'hhvm-server-'.md5($config).'.h 8000 df'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that this statement is true as of PHP 5.3 (but PHP 5.2 is not an issue anymore) |
||
file_put_contents($tmpfile, $config); | ||
$builder = new ProcessBuilder(array(PHP_BINARY, '-ms', "-c$tmpfile")); | ||
$builder->setWorkingDirectory($docroot); | ||
$builder->setTimeout(null); | ||
$builder->getProcess()->run(function ($type, $buffer) use ($output) { | ||
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { | ||
$output->write($buffer); | ||
} | ||
}); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be great use a parameter in order to lunch the HHVM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it makes sense. If you want to launch the built-in webserver, it seems logical to use HHVM to run the launching command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all the libraries works with HHVM, and having HHVM installed on my machine doesn't mean I want to use it for all the projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use HHVM for development
or fallback to php built-in web server if you hate HHVM ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👯 thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liuggio
defined('HHVM_VERSION')
does not check whether HHVM is installed on your machine. It checks whether you used HHVM to run the current process