把PHP代碼編譯成C/C++代碼,使你的php跑得更快

來源:互聯網
上載者:User

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
http://www.ooso.net/archives/557

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.