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 all commits
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
66 changes: 66 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 use 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,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';
Copy link
Member

Choose a reason for hiding this comment

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

DIRECTORY_SEPARATOR is not necessary for portability. Using / would be more readable.

Copy link
Member

Choose a reason for hiding this comment

The 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);
}
});
}

}
0