Note: These
code examples assume the HipHop compiler is fully built.
1 . Setting Up Your Environment (构建环境)
To get started, you need to configure two environment variables.
cd .. # into the root of the hphp checkout
export HPHP_HOME=`pwd`
export HPHP_LIB=`pwd`/bin
# if you followed the Ubuntu 9.10 instructions, you also need
export CMAKE_PREFIX_PATH=`/bin/pwd`/../
2 . Choosing which Mode to Run HipHop (HipHop运行模式)
You can run HipHop in 5 different modes. These Hello World examples demonstrate each one. All commands are run from the src/ directory in these examples.
First, create a file called test.php. Populate it with some text, like, “echo Hello, World! > test.php”. Then choose from the following modes:
Mode 1 (直接运行模式): Compiling HipHop and running it directly.
echo "Hello, World!" > test.php
hphp/hphp test.php
Mode 2 (命令行运行编译程序): Compiling HipHop in a temporary directory and running the compiled program from the command line.
hphp/hphp test.php --keep-tempdir=1 --log=3
/tmp/hphp_p6vSsP/program (use your own temporary directory name from output)
--keep-tempdir=1 can
also be specified with -k
1. Note it’s single dash and there is a space, not “=” between “k” and “1”. This is something to watch out when working with boost command line options.
--log=3 outputs
some verbose information, so you can find out which temporary directory it created. You may always specify your own output directory with --output-dir=mypath or -o
mypath.
Mode 3 (使用web 运行编译模程序 ): Compiling HipHop in a temporary directory and running the compiled program as a web server.
hphp/hphp test.php --keep-tempdir=1 --log=3
sudo /tmp/hphp_p6vSsP/program -m server
Then, from another window, run:
curl localhost/test.php
If you don’t want to use sudo, you can run HipHop on port 8080.
hphp/hphp test.php --keep-tempdir=1 --log=3
/tmp/hphp_p6vSsP/program -m server -p 8080
curl http://localhost:8080/test.php
Run this command to administer your server:
curl http://localhost:8080
You can also run the server as a daemon:
sudo /tmp/hphp_p6vSsP/program -m daemon
Mode 4 (直接解释运行): Interpreting HipHop directly.
hphpi/hphpi -f test.php (note the "-f" flag)
Mode
5 (web服务器运行源代码): Starting a Web server or daemon and interpreting HipHop on the fly.
sudo hphpi/hphpi -m server (or daemon)
curl localhost/test.php
curl localhost