github上面fork了一个老外的脚本,修改了一些bug和功能做的分支版本。支持操作系统ubuntu 12.04,别的系统暂时不支持。

安装方法:

$sudo su -
#apt-get install git-core
#git clone git://github.com/xianglei/easy-hiphop.git
#cd easy-hiphop/hiphop-php
#chmod +x install-no-hhvm.sh
#./install-no-hhvm.sh

install-no-hhvm是不带php vm的版本。可正确安装,install.sh带php vm,但是可能无法正确安装,建议安装不带虚拟机的版本。

安装完成后可执行文件在/home/dev/hiphop-php/src/hphp/hphp,脚本会创建一个链接文件到/usr/bin。所以,装好了直接敲hphp就可以用。如果出现HPHP_HOME未设置的错误,请执行

#source /etc/profile

或者

#export HPHP_HOME=/home/dev/hiphop-php

简单使用说明。

编译单个php文件。

#hphp --keep-tempdir=1 --log=4 test.php

编译一个目录

#hphp --keep-tempdir=1 --log=3 --input-dir=/path/to/your/php/source

编译文件到/tmp文件夹下找。

运行/tmp/hphp_xxxxxx/program -m server -p 8080

然后访问服务器的8080端口,url要输入原文件名。比如你编译单个test.php,需要在url里指定

http://localhost:8080/test.php

编译整个目录,hiphop不能为你指定默认访问文件,所以,即使你是index.php,url里面也要写上,当然也可以用指定默认首页的server参数方式启动。参看facebook wiki。

http://localhost:8080/index.php

hphp --help可以查看全部编译参数说明。
/tmp/hphp_xxxxxx/program --help可以查看全部启动选项。

附一个性能测试结果,ab访问默认url为nginx+php5.3,8080端口为hiphop编译后。

测试环境:ubuntu 12.04 in VirtualBox,内存1G,CPU*2

<?php
echo rand(0,10000);
?>

nginx+php:

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:                nginx/1.1.19
Server Hostname:                localhost
Server Port:                        80

Document Path:                    /easyhadoop/test.php
Document Length:                4 bytes

Concurrency Level:            200
Time taken for tests:     48.693 seconds
Complete requests:            100000
Failed requests:                10169
     (Connect: 0, Receive: 0, Length: 10169, Exceptions: 0)
Write errors:                     0
Non-2xx responses:            3
Total transferred:            16289226 bytes
HTML transferred:             389247 bytes
Requests per second:        2053.68 [#/sec] (mean)
Time per request:             97.386 [ms] (mean)
Time per request:             0.487 [ms] (mean, across all concurrent requests)
Transfer rate:                    326.69 [Kbytes/sec] received

Connection Times (ms)
                            min    mean[+/-sd] median     max
Connect:                0        1     1.7            0            37
Processing:         9     94 217.0         61     13281
Waiting:                8     94 217.0         61     13281
Total:                 42     95 217.1         62     13297


-------------------------------------

HipHop:

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:                
Server Hostname:                localhost
Server Port:                        8080

Document Path:                    /test.php
Document Length:                4 bytes

Concurrency Level:            200
Time taken for tests:     26.778 seconds
Complete requests:            100000
Failed requests:                10129
     (Connect: 0, Receive: 0, Length: 10129, Exceptions: 0)
Write errors:                     0
Total transferred:            10188711 bytes
HTML transferred:             388711 bytes
Requests per second:        3734.36 [#/sec] (mean)
Time per request:             53.557 [ms] (mean)
Time per request:             0.268 [ms] (mean, across all concurrent requests)
Transfer rate:                    371.57 [Kbytes/sec] received

Connection Times (ms)
                            min    mean[+/-sd] median     max
Connect:                0     16 154.5            0     15032
Processing:        10     36    65.5         35     13901
Waiting:                7     35    65.5         34     13900
Total:                 28     52 176.0         35     15066

均是100000个request,200个concurrency。试过开到500个concurrency,nginx直接挂了。hiphop还能跑。

nginx 4进程+php4进程ab测试处理请求2000个每秒,响应时间0.48秒。

hiphop 单进程,ab测试处理请求3700个每秒,响应时间0.26秒。

无论是请求数还是响应时间都大大提高。

运行参数可参看facebook官方wiki