HipHop 學習研究

來源:互聯網
上載者:User

HipHop 將PHP代碼轉換為高度最佳化的C++代碼,然後再用g++編譯器編譯。

HipHop產生的程式碼儘可能地使用函數和變數的靜態繫結。
轉換過程分三步: 
1. 靜態分析。收集聲明關係和依賴關係等資訊。 
2. 類型推演。選擇最合適的類型,是C++的標量?還是String, Array, classes, Object或者Variant。 
3. 代碼產生。大部分直接將PHP語句和運算式對應為C++的語句和運算式。

hiphop編譯完成只是hiphop的開始 -> hiphop內建了hphpi伺服器

HPHPi,是一個實驗性的解譯器。通過它,不編譯PHP原始碼也可以運行。它已經用於HipHop自身的調試中。

註:nginx並不是必須的,如果需要的話也是拿來做前端代理,帶入一些使用者需要的web伺服器附加功能。

安裝好環境後

編譯前配置:

setenv HPHP_HOME /usr/local/src/freebsd-hiphop-php
setenv HPHP_LIB /usr/local/src/freebsd-hiphop-php/bin
setenv CMAKE_PREFIX_PATH /services/hipop-php-include
setenv CC /usr/local/bin/gcc44
setenv CXX /usr/local/bin/g++44

編譯 1 單個檔案
1. /usr/local/src/freebsd-hiphop-php/src/hphp/hphp test.php --keep-tempdir=1 --log=3
2. /tmp/hphp_p6vSsP/program -m server -p 8080
3. curl http://localhost:8080/test.php

編譯 2 多個檔案
1. find . -name "*.*" > files.list
2. /usr/local/src/freebsd-hiphop-php/src/hphp/hphp --input-list=files.list -k 1 --log=3 --include-path="." --output-dir=/tmp/test --force=1 --cluster-count=50 -v "AllDynamic=true" -v "AllVolatile=true"
3. /tmp/hphp_DwhCB8/program -m server -v "Server.SourceRoot=/tmp/hphp_DwhCB8" -v "Server.DefaultDocument=index.php" -c /usr/local/src/freebsd-hiphop-php/bin/mime.hdf -p 8080

用hphpi編譯執行個體
1. /usr/local/src/freebsd-hiphop-php/src/hphpi/hphpi -f curlTest.php
2. sudo /usr/local/src/freebsd-hiphop-php/src/hphpi/hphpi -m server -p 8088

hphp編譯後的program是一個完整的網站,能自己監聽連接埠,無需apache,nginx等web伺服器

註:
1. 編譯常用選項  hphp/hphp
 --input-list=files.list //多個檔案用(單個檔案直接寫檔案名稱字)
 --keep-tempdir=1   //[簡寫:-k 1]
 --log=3 //指明編譯的log等級 ,一般啟用3,有用的資訊都打出來
 --force=1 //即便遇到warning和error都強制編譯代碼 ,錯誤和警報會在報告中體現出來
 --gen-stats=1 //是否需要產生代碼狀態和代碼錯誤報表
 --include-path="." //include包含語句中出現的代碼檔案目錄
 --cluster-count=50  //如果不配這個參數的話,有幾個php檔案就會產生幾個cpp檔案,導致編譯過程變長。所以如果基數過大的話,可以啟用這個參數
 --output-dir=/tmp  //編譯完成檔案存放目錄,預設在/tmp下
 --program=projectname //
 -v "AllDynamic=true" //支援動態函數調用和動態方法引動過程
 -v "AllVolatile=true" //可以支援動態函數和類的聲明

2. 運行 參數如下
./program 
Options:
--help display this message
-m [ --mode ] arg (=run) run | server | daemon | replay | translate
-c [ --config ] arg load specified config file
-v [ --config-value ] arg individual configuration string in a format
of name=value, where name can be any valid
configuration for a config file
-p [ --port ] arg (=-1) start an HTTP server at specified port
--admin-port arg (=-1) start admin listerner at specified port
-u [ --user ] arg run server under this user account
-f [ --file ] arg executing specified file
--count arg (=1) how many times to repeat execution
--no-safe-access-check arg (=0) whether to ignore safe file access check
--arg arg arguments
--extra-header arg extra-header to add to log lines
--build-id arg unique identifier of compiled server code
--xhprof-flags arg (=0) Set XHProf flags

官方:
https://github.com/facebook/hiphop-php

https://github.com/facebook/hiphop-php/wiki/using-nginx-as-front-server-to-hiphop

運行hiphop
https://github.com/facebook/hiphop-php/wiki/running-hiphop
運行時選項
https://github.com/facebook/hiphop-php/wiki/Runtime-options

其他參考

http://xenojoshua.com/tag/hiphop-php/

http://huichen.org/en/2010/07/hiphop-for-freebsd/

http://blog.csdn.net/cyberexp2008/article/details/6756826

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.