背景:HipHop是Facebook在今年早些時(shí)候放出的一個(gè)php開源項(xiàng)目,主要的特征就是把php翻譯成了c++執(zhí)行,HipHop所帶來(lái)的性能提升用Facebook官方博客上項(xiàng)目負(fù)責(zé)人趙海平的話說(shuō):
With HipHop we’ve reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead. This project has had a tremendous impact on Facebook.
HipHop的官網(wǎng)是http://github.com/facebook/hiphop-php,上面有說(shuō)明了HipHop的安裝步驟,但是我個(gè)人感覺那還是不夠詳細(xì)具體的,實(shí)際的安裝過(guò)程中會(huì)碰到了不少問(wèn)題。
在此我詳細(xì)羅列出安裝步驟和分享出解決所碰到問(wèn)題的過(guò)程和方法,以便能幫助到那些喜愛php技術(shù),想要了解HipHop的人,能對(duì)HipHop有更深層次的認(rèn)識(shí)。
我的環(huán)境準(zhǔn)備: Centos 5.5 64bit,Corei7 860,4G內(nèi)存(注意:內(nèi)存不能太小,HipHop在make時(shí)候和運(yùn)行時(shí)候是很耗內(nèi)存的;操作系統(tǒng)最好為64位)
開始安裝:
1.切換到root賬號(hào)并建立/root/bulid目錄
[root@localhost ~]# mkdir build
[root@localhost ~]# cd build
2.安裝rpmforge
[root@localhost build]# wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
[root@localhost build]# rpm -import http://apt.sw.be/RPM-GPG-KEY.dag.txt
[root@localhost build]# rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm
[root@localhost build]# rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm
[root@localhost build]# yum check-update
[root@localhost build]# vim /etc/yum.repos.d/rpmforge.repo 修改enabled = 0
3.直接先用yum安裝一些HipHop需要的基礎(chǔ)包
binutils \
binutils-devel \
bison \
cmake \
curl-devel \
distcc \
expat \
gcc \
gcc-c++ \
gd \
gd-devel \
git \
libcap-devel \
libevent-devel \
libmcrypt-devel \
libssh2 \
libxml2-devel \
openssl-devel \
pcre-devel \
re2c \
flex \
zlib \
--enablerepo=rpmforge
4.安裝perl git
[root@localhost build]# rpm -U perl-Git-1.5.6.1-1.x86_64.rpm
5.安裝tbb
[root@localhost build]# tar xvzf tbb30_20100406oss_lin.tgz
[root@localhost build]# export TBB_INSTALL_DIR="/root/build/tbb30_20100406oss"
[root@localhost build]# export TBB_ARCH_PLATFORM="intel64/cc4.1.0_libc2.4_kernel2.6.16.21"
注意:我一開始cmake的時(shí)候,總會(huì)報(bào)Could NOT find TBB library的錯(cuò)誤,分析了hiphop-php/CMake/FindTBB.cmake源碼后,發(fā)現(xiàn)167行為:
改為
后即可。
因此我得出一個(gè)結(jié)論,當(dāng)你配置好了環(huán)境變量而cmake的時(shí)候又提示你找不到這個(gè)lib的時(shí)候,本身的cmake文件和你下載下來(lái)的的lib不匹配就可能導(dǎo)致此問(wèn)題,解決的辦法即是直接修改cmake文件,滿足符合你的需要。
當(dāng)然還會(huì)有其他可能導(dǎo)致類似的問(wèn)題,我接下去會(huì)說(shuō)。
6.通過(guò)rpm包安裝boost和icu庫(kù)
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/boost-devel-1.37.0-1.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/icu-4.2.1-6.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/libicu-4.2.1-6.x86_64.rpm/download
[root@localhost build]# wget http://sourceforge.net/projects/hphp/files/CentOS%205%2064bit/RPM/libicu-devel-4.2.1-6.x86_64.rpm/download
[root@localhost build]# rpm -ivh \
icu-4.2.1-6.x86_64.rpm \
libicu-4.2.1-6.x86_64.rpmm \
libicu-devel-4.2.1-6.x86_64.rpm \
boost-1.37.0-1.x86_64.rpm \
boost-devel-1.37.0-1.x86_64.rpm
7.安裝Oniguruma
[root@localhost build]# tar xvfz onig-5.9.2.tar.gz
[root@localhost build]# cd onig-5.9.2
[root@localhost onig-5.9.2]# ./configure && make && sudo make install
[root@localhost onig-5.9.2]# cd ..
8.下載HipHop
9.安裝libevent
[root@localhost build]# tar xvzf libevent-1.4.13-stable.tar.gz
[root@localhost build]# cd libevent-1.4.13-stable
[root@localhost libevent-1.4.13-stable]# cp ../hiphop-php/src/third_party/libevent-1.4.13.fb-changes.diff .
[root@localhost libevent-1.4.13-stable]# patch -p1 < libevent-1.4.13.fb-changes.diff
[root@localhost libevent-1.4.13-stable]# ./configure && make && make install
[root@localhost libevent-1.4.13-stable]# cp .libs/libevent.so /usr/lib64/libevent.so
[root@localhost libevent-1.4.13-stable]# cd ..
10.安裝curl
[root@localhost build]# tar xvzf curl-7.20.0.tar.gz
[root@localhost build]# cd curl-7.20.0
[root@localhost curl-7.20.0]# cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
[root@localhost curl-7.20.0]# patch -p1 < libcurl.fb-changes.diff
[root@localhost curl-7.20.0]# ./configure && make && make install
[root@localhost curl-7.20.0]# cp .libs/libcurl.so /usr/lib64/libcurl.so
[root@localhost curl-7.20.0]# cd ..
11.安裝MySQL
[root@localhost build]# tar zxvf mysql-5.5.3-m3.tar.gz
[root@localhost build]# cd mysql-5.5.3-m3/
[root@localhost mysql-5.5.3-m3]# ./configure --prefix=/root/bulid/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
[root@localhost mysql-5.5.3-m3]# make && make install
[root@localhost mysql-5.5.3-m3]# cd ..
[root@localhost build]# export MYSQL_DIR="/root/bulid/mysql"
[root@localhost build]# vi hiphop-php/CMake/FindMySQL.cmake
刪除33行$ENV{MYSQL_INCLUDE_DIR}
刪除70行$ENV{MYSQL_DIR}/libmysql_r/.libs
刪除71行$ENV{MYSQL_DIR}/lib
12.安裝libmemcached,要先裝memcached
[root@localhost build]# wget http://launchpad.net/libmemcached/1.0/0.42/+download/libmemcached-0.42.tar.gz
[root@localhost build]# tar zxvf memcached-1.4.5.tar.gz
[root@localhost build]# cd memcached-1.4.5
[root@localhost memcached-1.4.5]# ./configure --with-libevent=/root/build/libevent-1.4.1/
[root@localhost memcached-1.4.5]# make && make install
[root@localhost memcached-1.4.5]# cd ../libmemcached-0.42
[root@localhost libmemcached-0.42]# ./configure --with-memcached-dir=/root/build/memcached-1.4.5
[root@localhost libmemcached-0.42]# make && make install
[root@localhost libmemcached-0.42]# cd ..
13.cmake HipHop
[root@localhost build]# cd hiphop-php/
[root@localhost hiphop-php]# git submodule init
[root@localhost hiphop-php]# git submodule update
[root@localhost hiphop-php]# export HPHP_HOME=`pwd`
[root@localhost hiphop-php]# export HPHP_LIB=`pwd`/bin
[root@localhost hiphop-php]# cmake .
cmake列表
-- MySQL client libraries: mysqlclient_r
-- Found libevent: /usr/lib64/libevent.so
-- Found GD: /usr/lib64/libgd.so
-- Found ICU header files in /usr/include
-- Found ICU libraries: /usr/lib64/libicuuc.so
-- Skipping TCmalloc
-- Found Intel TBB
-- Found mcrypt: /usr/lib/libmcrypt.so
-- Looking for arpa/inet.h
-- Looking for arpa/inet.h - found
-- Looking for netinet/in.h
-- Looking for netinet/in.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for sys/socket.h
-- Looking for sys/socket.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ssize_t
-- Check size of ssize_t - done
-- Check size of uint32_t
-- Check size of uint32_t - done
-- Check size of uint8_t
-- Check size of uint8_t - done
-- Looking for AF_LOCAL
-- Looking for AF_LOCAL - found
-- Looking for PF_LOCAL
-- Looking for PF_LOCAL - found
-- Looking for memset
-- Looking for memset - found
-- Looking for socket
-- Looking for socket - found
-- Looking for strerror
-- Looking for strerror - found
-- Found libevent: /usr/lib64/libevent.so
-- Looking for event_get_version_number
-- Looking for event_get_version_number - found.
-- Performing Test HAVE_LIBEVENT_145
-- Performing Test HAVE_LIBEVENT_145 - Success
-- Found libevent 1.4.5+
-- Looking for include files INCLUDE_CHECK_stdlib.h
-- Looking for include files INCLUDE_CHECK_stdlib.h - found
-- Looking for include files INCLUDE_CHECK_assert.h
-- Looking for include files INCLUDE_CHECK_assert.h - found
-- Looking for strcasecmp
-- Looking for strcasecmp - found
-- Looking for strchr
-- Looking for strchr - found
-- Downloading 8859-1.TXT
-- Downloading 8859-2.TXT
-- Downloading 8859-3.TXT
-- Downloading 8859-4.TXT
-- Downloading 8859-5.TXT
-- Downloading 8859-6.TXT
-- Downloading 8859-7.TXT
-- Downloading 8859-8.TXT
-- Downloading 8859-9.TXT
-- Downloading 8859-10.TXT
-- Downloading 8859-11.TXT
-- Downloading 8859-13.TXT
-- Downloading 8859-14.TXT
-- Downloading 8859-15.TXT
-- Downloading 8859-16.TXT
-- Downloading EastAsianWidth.txt
-- Looking for include files HAVE_SYS_STAT_H
-- Looking for include files HAVE_SYS_STAT_H - found
-- Looking for include files HAVE_STDLIB_H
-- Looking for include files HAVE_STDLIB_H - found
-- Looking for include files HAVE_STRING_H
-- Looking for include files HAVE_STRING_H - found
-- Looking for include files HAVE_MEMORY_H
-- Looking for include files HAVE_MEMORY_H - found
-- Looking for include files HAVE_STRINGS_H
-- Looking for include files HAVE_STRINGS_H - found
-- Looking for include files HAVE_INTTYPES_H
-- Looking for include files HAVE_INTTYPES_H - found
-- Looking for include files HAVE_UNISTD_H
-- Looking for include files HAVE_UNISTD_H - found
-- Looking for include files HAVE_DLFCN_H
-- Looking for include files HAVE_DLFCN_H - found
-- Looking for fdatasync
-- Looking for fdatasync - found
-- Looking for usleep
-- Looking for usleep - found
-- Looking for fullfsync
-- Looking for fullfsync - found
-- Looking for localtime_r
-- Looking for localtime_r - found
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Check if the system is big endian
-- Searching 16 bit integer
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for include files HAVE_LOCALE_H
-- Looking for include files HAVE_LOCALE_H - found
-- Looking for include files HAVE_LIMITS_H
-- Looking for include files HAVE_LIMITS_H - found
-- Check size of int32_t
-- Check size of int32_t - done
-- Looking for strtoll
-- Looking for strtoll - found
-- Looking for atoll
-- Looking for atoll - found
-- Looking for strftime
-- Looking for strftime - found
-- Looking for setlocale
-- Looking for setlocale - found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/build/hiphop-php
cmake一般出錯(cuò)就是提示庫(kù)找不到,原因出了之前說(shuō)的那種外還有可能是程序找的/usr/lib/libxxx.so,而這個(gè)lib本身叫/usr/lib/libxxx.so.1,因此你需要cp一份或是ln,讓程序能找得到。
14.make HipHop,離勝利僅僅一步之遙了!
make的時(shí)候很耗cpu和內(nèi)存的,因此想在vps上玩HipHop的同學(xué)要注意了,有可能程序會(huì)卡死。
追到ext_mysql.cpp的722行后看到有如下語(yǔ)句:
722 mysql = mysql->last_used_con;
723 if (!mysql->fields) return true;
724 if (mysql->status != MYSQL_STATUS_GET_RESULT) {
725 // consistent with php_mysql_do_query_general
726 return true;
727 }
我查詢了mysql-5.5.3的源碼后,發(fā)現(xiàn)MYSQL的定義并沒(méi)有l(wèi)ast_used_con,結(jié)構(gòu)如下:
{
NET net; /* Communication parameters */
unsigned char *connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
char *info, *db;
struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
my_ulonglong extra_info; /* Not used */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag,server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count;
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
my_bool reconnect; /* set to 1 if automatic reconnect */
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
my_bool unused1;
void *unused2, *unused3, *unused4, *unused5;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
void *thd;
/*
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
from mysql_stmt_close if close had to cancel result set of this object.
*/
my_bool *unbuffered_fetch_owner;
/* needed for embedded server - no net buffer to store the 'info' */
char *info_buffer;
void *extension;
} MYSQL;
然后我google追了下mysql之前的源碼,是有過(guò)存在last_used_con的時(shí)期,但是后來(lái)已經(jīng)被mysql的開發(fā)人員廢棄了,因此我 懷疑這個(gè)有可能是HipHop在開發(fā)的時(shí)候MYSQL的結(jié)構(gòu)里還有l(wèi)ast_used_con,但是我下載的mysql庫(kù)已經(jīng)沒(méi)有,所以導(dǎo)致此問(wèn)題。
我把722的mysql = mysql->last_used_con;刪除后重新make就沒(méi)有問(wèn)題了。
還有一點(diǎn)需要注意的是:如果是你在cmake階段出現(xiàn)的問(wèn)題,但是在make階段暴露了,你需要重新cmake的時(shí)候你需要移除hiphop-php/CMakeCache.txt文件。
到此,HipHop的安裝就算告一段落,還是比較繁瑣的,希望以后facebook能簡(jiǎn)化這個(gè)過(guò)程。
未來(lái)的文章里我會(huì)對(duì)HipHop的應(yīng)用有持續(xù)的說(shuō)明,比如它如何編譯smarty,以及各種環(huán)境性能的測(cè)試比較,盡請(qǐng)期待!
本站文章皆為原創(chuàng),如需轉(zhuǎn)載,請(qǐng)注明出處:http://blog.liubijian.com/hiphop-php-install.html和本站聲明,謝謝!