8000 [FrameworkBundle] Add HHVM support for built-in web server by RickySu · Pull Request #10017 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add hhvm server run support
  • Loading branch information
RickySu committed Jan 14, 2014
commit 5cad296d72b6438d8f50783fa6240b880cb886cc
70 changes: 70 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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 u 10000 se it for all the projects.

Copy link
Contributor Author

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

hhvm app/console server:run

or fallback to php built-in web server if you hate HHVM ;)

app/console server:run

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👯 thanks

Copy link
Member

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

$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);
Expand All @@ -101,4 +106,69 @@ 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 = tempnam(sys_get_temp_dir(), 'symfony_hhvm_config');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the file in app/cache and have a constant name for it (example: the hash of the its content) to avoid creating a new temporary file when you launch the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💚

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, &$tmpfile) {
if (null !== $tmpfile) {
unlink($tmpfile);
$tmpfile = null;
}
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$output->write($buffer);
}
});
}

}
0