Move from PHP to HHVM to improve websites performance

For a long time ago, I’m not writing any article about the server (nginx) optimization because my VPS that’s powered by Digital Ocean is working flawlessly on the lowest plan with just $5/month.
Do you know? If you do over optimization on the lowest VPS hardware on Digital Ocean, it will decrease your server performance instead the good results which you’ve expected. Although it can’t improve by itself, you really want to make it… better by switch from php-fpm to hhvm.

What’s HHVM

HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the development flexibility that PHP provides.

Is that better than PHP-FPM?

You can find a ton of comparison between HHVM and PHP-FPM by Google. I won’t go into details here but I show you a small result that I’ve tested with Apache Bench (ab).
I’ll make 100 requests, one at a time, to the VPS running Nginx + PHP-FPM and Nginx + HHVM. I’m doing a concurrency of one, to test how fast each configs can handle the single requests.

Benchmarking HHVM

$ ab -c 1 -n 100
Concurrency Level:      1
Time taken for tests:   12.110 seconds
Complete requests:      100
Failed requests:        0
Requests per second:    8.26 [#/sec] (mean)
Time per request:       121.103 [ms] (mean)

That’s 0.12 seconds per page request on HHVM.

Benchmarking PHP-FPM

$ ab -c 1 -n 100
Concurrency Level:      1
Time taken for tests:   35.198 seconds
Complete requests:      100
Failed requests:        1
   (Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Requests per second:    2.85 [#/sec] (mean)
Time per request:       351.186 [ms] (mean)

The numbers speak for themselves.

Compare HHVM and PHP-FPM
Compare HHVM and PHP-FPM

How to switch to HHVM from PHP-FPM?

It’s very easy when you have an installed VPS, I don’t guide you to setup your own VPS from the scratch, if you want, you can read my articles about LEMP on Digital Ocean

Install HHVM

$ sudo pacman -S hhvm

Enable and Start the HHVM service

$ sudo systemctl start hhvm
$ sudo systemctl enable hhvm

Configure nginx to use HHVM instead PHP-FPM

If you used FastCGI by default, you don’t need to change the configuration of your nginx, just stop php-fpm service then restart nginx to make it work.
If you don’t use FastCGI, just edit /etc/nginx/nginx.conf:

location ~ \.php$ {
   fastcgi_index  index.php;
   include        fastcgi.conf;

In absolute basic terms, this is saying, whenever the web server is asked to display a PHP file then this rule will take effect.
Don’t forget to stop php-fpm service then restart nginx. That’s what.
However, if this post doesn’t help you, maybe use the comments below to see if you can help others’ or other folk can help you?

nginx, wordpress optimization


  1. This fascinating. I’m looking forward to implementing this is my own machines. Sloppy response times are frustrating me on some instances. Thanks love your work.!

  2. Your stats look very promising – thank you for sharing.
    Does this also work with forced site-wide SSL ?

Add a Comment

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

Comment *
Name *
Email *

This site uses Akismet to reduce spam. Learn how your comment data is processed.