Option: Use hhvm to speed up!

hhvm is a virtual machine for executing programs in PHP (and HACK). It provides great performance with the flexibility of PHP, it uses a just-in-time (JIT) compiler which applies several optimizations that can boost our applications. You really will notice the difference.

It can be configured as a CGI server (as PHP-FPM), but we have one freat drawback in my opinion: it’s not (in march 2014) as stable as I’d like. I have encoutered some bugs that make me doubt if I would use it in production. Also it’s not pure PHP so many things won’t work (Facebook is doing a great job to support lots of common frameworks, but still in progress)

But, for testing purposes it’s ok, so let’s install it. It’s better to go here for installation instructions in many distributions. Then install hhvm-fastcgi package which will make hhvm run as a FastCGI daemon.

Then, edit you VirtualHost file (using the example here as base, and putting in bold changes):

<VirtualHost *:80>
        ServerAdmin info@totaki.com
        ServerName totaki.com
        ServerAlias www.totaki.com

        DocumentRoot /home/cloud/www/totaki.com/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        <IfModule mod_fastcgi.c>
                AddHandler hhvm-fcgi .php
                Action hhvm-fcgi /hhvm-fcgi
                Alias /hhvm-fcgi /usr/bin/hhvm
                FastCgiExternalServer /usr/bin/hhvm -host -pass-header Authorization -pass-header Content-type
        <Directory /home/cloud/www/totaki.com/www/>
                 Options FollowSymLinks MultiViews
                 AllowOverride All
                 Order allow,deny
                 allow from all
         ErrorLog    "/home/cloud/www/totaki.com/logs/error.log"        
         LogLevel warn
         CustomLog "/home/cloud/www/totaki.com/logs/access.log" combined        

And that’s it, restart Apache and your next page will be loaded by hhvm. With this configuration, you can easily switch between hhvm and PHP-FPM, so if hhvm gives you any problem, you can disable it.

Leave a Reply

Your email address will not be published. Required fields are marked *