您的位置:首页 > 编程语言 > C语言/C++

把PHP代码编译成C/C++代码,使你的php跑得更快

2016-02-01 00:00 645 查看
http://blog.163.com/lgh_2002/blog/static/4401752620113635721100/

FaceBook 发布了一款能将php代码转换为C++的工具,hiphop, 如果你的网站很大,类似新浪这样的大型门户,可以考虑。

目前已经在CentOS和ubuntu等Linux服务器上编译通过。

安装:

一、需要依赖的包

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

下面的包需要在源代码的基础上打补丁

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

二、指定CMake的位置

export CMAKE_PREFIX_PATH=/home/user

三、编译

cd /home/user/dev

git clone git://github.com/facebook/hiphop-php.git

cd hiphop-php

git submodule init

git submodule update

export HPHP_HOME=`pwd`

export HPHP_LIB=`pwd`/bin

make

cmake .

据fackbook说,可以提高50%左右的性能,前提是php代码中不能含有eval这种很少用的方法。

四、使用hphp

环境设置:

cd .. # 进入hphp的根目录,源码的存放目录

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

有若干种模式

1:直接编译为c++代码并执行

hphp/hphp test.php

2:编译到一个临时文件夹,并执行编译好的c++程序

hphp/hphp test.php --keep-tempdir=1 --log=3

/tmp/hphp_p6vSsP/program 这个根据你自己生成的运行

3:编译php为一个服务,并在指定端口运行

hphp/hphp test.php --keep-tempdir=1 --log=3

/tmp/hphp_p6vSsP/program -m server -p 8080

curl http://localhost:8080/test.php
sudo /tmp/hphp_p6vSsP/program -m daemon

参考:

https://github.com/facebook/hiphop-php/wiki/Running-HipHop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: