HipHop PHP实战(详解web运行模式)

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.

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.  

   Mode 2 (命令行运行编译程序  ): Compiling HipHop in a temporary directory and running the compiled program from the command line. 

--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.

Then, from another window, run:

If you don’t want to use sudo, you can run HipHop on port 8080.

Run this command to administer your server:

You can also run the server as a daemon:

  Mode 4 (直接解释运行): Interpreting HipHop directly.

Mode 5 (web服务器运行源代码): Starting a Web server or daemon and interpreting HipHop on the fly.

curl localhost/test.php其实就是客户端浏览器访问模式,好多人都问hiphop怎么和web服务器结合?  


其实HipHop可以当作web服务器来运行,说白了hphpi/hphpi -m server就是监听个端口守护进程,默认是80端口。





1)sudo src/hphpi/hphpi -m server相当apache的守护进程启动,并监听80端口。








   cp  test.php   test/ 



3. Compiling a Large Codebase (编译代码库)

First, familiarize yourself with the various of switches of the compiler:

There are 3 ways to specify some flags. 

(1) by a configuration file in HDF format. Please read doc/hdf for more details with the format. Then use--config to specify the config file. 

(2) For almost every option in HDF file, you can list it directly in its dot notation format. For example,-v "node.subnode=value"

(3) We created some shortcuts for most frequently used ones. They will look like --force.

The most important flags to learn are the ones for including or excluding files and directories. They were not designed cleanly and we may have to improve the way how they work. When in doubt, simply use the --input-list switch to take a list of file names prepared in a separate file.

You can get all the possible flags here: Runtime options

Using Parse-on-demand Mode (optional)

You can include files that are not specified from the command line into the compilation only if the compiler can determine where to find them. This means your include statements themselves are either:

  • Formed by simple literals; so the compiler can compute them during compilation time.

  • Written in simple form like "include_once $MY_ROOT.'/path/file.php';"
    Note: You can tell the compiler where to look for $MY_ROOT by creating a configuration file with content like this:

Use --config to include this configuration file. The compiler resolves the above include statement as “lib/my_code/path/file.php”.

Note: If you find parse-on-demand mode difficult to configure, try using --input-list to include every PHP file you want to compile.

Using distcc

For large compilations, we recommend setting up distcc.

4 . Example: Compiling PHPUnit

1. Check out PHPUnit’s PHP files:

2. We will use the safest and the cleanest way to specify input files,

This prepares a list of all PHP files we want to compile.

3. Now we’re ready to compile the project.

-k 1 or --keep-tempdir=1 so it creates a new temporary directory every time. This is convenient when you’re experimenting the compilation.

The --include-path is needed, because PHPUnit has file includes relative to root directory of phpunit. Without specifying this option, all includes in a format of “include ‘somepath/file.php’;” will be treated as relative path to the containing file.

--force=1 is needed to ignore warnings and errors HipHop found in the code. Without this option, the compiler will halt and dump out the errors on the screen, if any. With --force=1, those errors will mostly turn into run-time ones, and you may still find them in CodeError.js generated under the output directory.

--cluster-count=50 helps compilation, with or without distcc. Without this flag, each PHP file generates one .cpp file. When the number of PHPfiles is large, we may end up with too many .cpp files to compile. With clustering, no matter how many PHP files we have, HipHop will generate roughly the specified number of .cpp files, so it’s easier to feed them into distcc with fewer rounds. What we found is, cluster count should be slightly smaller than number of distcc workers. For example, if you have 20 machines each with 8 distcc workers, cluster count of 100 may be suitable. But one should change the numbers up and down to compare compilation time to find out the optimal value.

-v "AllDynamic=true" With this option, we can support dynamic function calls and dynamic method calls without any problems. Recommended to turn on, if coding has them. It will sacrifice performance a little bit, but it’s safe to have it.

-v "AllVolatile=true" With this option, we can support dynamic declarations of functions and classes without any problems. This is not recommended to turn on, unless your coding has crazy testing of function_exists() or class_exists() before or after declarations and the order is meaningful. PHPUnit happens to call get_declared_classes() before and after loading some class files and compare their returns to find new classes. Therefore, we need to add this switch to PHPUnit. Most likely, you don’t have to. It sacrifices performance in various degrees.

4. Now you should have a compiled PHPUnit binary. Report any problems to us, if you cannot reach this far. To run the binary,



Building and Installing on Ubuntu 11.10

  • Page History

1、Packages installation (安装依赖的包):

  • cmake 2.6 is the minimum version

  • g++/gcc 4.3 is the minimum version

  • Boost 1.37 is the minimum version

  • flex

  • bison

  • re2c

  • libmysql

  • libxml2

  • libmcrypt

  • libicu 4.2 is the minimum version

  • openssl

  • binutils

  • libcap

  • gd

  • zlib

  • tbb Intel's Thread Building Blocks

  • Oniguruma

  • libpcre

  • libexpat

  • libmemcached

The following packages have had slight modifications added to them. Patches are provided and should be made against the current source copies.

  • libcurl

  • src/third_party/libcurl.fb-changes.diff

  • libevent 1.4

  • src/third_party/libevent-1.4.13.fb-changes.diff OR src/third_party/libevent-1.4.14.fb-changes.diff

Using sudo or as root user:

As outlined in the 11.04 instructions plus the addition of the required libcloog-ppl0 package for 11.10

2、Getting HipHop source-code(获取HipHop源码包

3. Building third-party libraries 安装第三方库

1) libevent

 2) libCurl 安装libcurl

Make sure that your system time is correct, otherwise ./configure will fail.(确保系统时间正确,否则 ./configure 会出错.

As per:

  • Edit lib/ssluse.c

As per:

  • Edit runtime/ext/extension.cpp


make install    

cd ..  


3 )libmemcached (安装libmemcached库)

  1. wget    

  2. tar -xzvf libmemcached-0.49.tar.gz    

  3. cd libmemcached-0.49    

  4. ./configure –prefix=$CMAKE_PREFIX_PATH    

4. Building HipHop(安装Hiphop)

hphp binary can be found in src/hphp folder and is called hphp

If any errors occur, it may be required to remove the CMakeCache.txt directory in the checkout.

If your failure was on the make command, try to correct the error and run make again, it should restart from the point it stops. If don’t, try to remove as explained above.








友情链接:万达主管QQ  万达娱乐注册  万达注册  万达直属QQ  万达开户  万达娱乐开户  万达娱乐主管  万达娱乐注册  万达主管