-
Notifications
You must be signed in to change notification settings - Fork 3k
Running PHP programs with HHVM
First, create hello.php
:
<?php echo 'Hello from Hiphop'; ?>
Here's how to run a PHP program at the command line:
hhvm hello.php
Next, run hhvm as a server (if you installed from source it is in hphp/hhvm/hhvm
):
sudo hhvm -m server
And it is that easy:
curl localhost/hello.php
If you want to set a port number, add -p option as below.
hhvm -m server -p 8000
To get some more performance (10% - 25%) out of your scripts, you can use RepoAuthoritative mode. Note that RepoAuthoritative mode does not support eval(), and it is not recommended unless you really need that last additional bit of performance in a production environment.
Using RepoAuthoritative mode requires doing a "build" step to produce a bytecode archive in advance. If you have PHP files file1.php
and file2.php
, you can build a bytecode archive named hhvm.hhbc
by executing this command:
hhvm --hphp -thhbc -o some_dir file1.php file2.php
Now you will have a pre-compiled archive file named some_dir/hhvm.hhbc
. The file hhvm.hhbc
is actually an sqlite database file - you can even view the structure of the file using sqlite. This is similar to a java .jar
or a python .par
file. It is a stand-alone version of your scripts. To run the program file1.php
, use this command:
hhvm -vRepo.Authoritative=true -vRepo.Central.Path=some_dir/hhvm.hhbc file1.php
To run the program file2.php
, use this command:
hhvm -vRepo.Authoritative=true -vRepo.Central.Path=some_dir/hhvm.hhbc file2.php
Note: If you get the error message Unable to find/load systemlib.php
, make sure you are pointing at the hhvm.hhbc
file and not the directory.
For more complicated setups, you'll want to create a config.hdf
file. See the documentation for possible options. Then run it like:
hphp/hhvm/hhvm -m server -c config.hdf