Permalink
Browse files

[FrameworkBundle] Add HHVM support for built-in web server

  • Loading branch information...
1 parent fff29a3 commit 66798ba9046ea6612a861fd65903bc1b867d714b @RickySu RickySu committed with fabpot Jan 14, 2014
Showing with 66 additions and 0 deletions.
  1. +66 −0 src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
@@ -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).'.hdf';
+ 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);
+ }
+ });
+ }
+
}

0 comments on commit 66798ba

Please sign in to comment.