新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHPFFI允許在PHP腳本中嵌入C代碼
Zend 的 Dmitry Stogov 通過允許 PHP 執(zhí)行嵌入式 C 代碼擴展了 PHP 的領域。 這將允許完全訪問本地 C 函數(shù),變量以及數(shù)據(jù)結(jié)構。

專注于為中小企業(yè)提供網(wǎng)站制作、網(wǎng)站設計服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)涼山州免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了1000多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
解決方案 PHP FFI 作為實驗性擴展提供,但要求 PHP 7.3 的開發(fā)版本。 該解決方案還不能用于生產(chǎn),但它構建在堅實的基礎之上,使用 FFI(外部函數(shù)接口)庫 libffi,允許高級語言生成代碼。
輸入:
- int printf(const char *format, ...);
- char * getenv(const char *);
- unsigned int time(unsigned int *);
- typedef unsigned int time_t;
- typedef unsigned int suseconds_t;
- struct timeval {
- time_t tv_sec;
- suseconds_t tv_usec;
- };
- struct timezone {
- int tz_minuteswest;
- int tz_dsttime;
- };
- int gettimeofday(struct timeval *tv, struct timezone *tz);
- ", "libc.so.6");$libc->printf("Hello World from %s!\n", "PHP");
- var_dump($libc->getenv("PATH"));
- var_dump($libc->time(null));$tv = $libc->new("struct timeval");$tz = $libc->new("struct timezone");$libc->gettimeofday($tv, $tz);
- var_dump($tv->tv_sec, $tv->tv_usec, $tz);?>
將輸出:
- Hello World from PHP!
- string(135) "/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/dmitry/.local/bin:/home/dmitry/bin"int(1523617815)
- int(1523617815)
- int(977765)
- object(CData)#3 (2) {
- ["tz_minuteswest"]=>
- int(-180)
- ["tz_dsttime"]=>
- int(0)
- }
FFI 目前的數(shù)據(jù)結(jié)構訪問還比較緩慢,比訪問原始 PHP 數(shù)組和對象的速度慢大約 4 倍?,F(xiàn)階段的速度雖然不太樂觀,但還是可以幫助節(jié)省內(nèi)存和資金的。
隨著 PHP FFI 后續(xù)的不斷優(yōu)化,性能還會不斷提升。
當前題目:PHPFFI允許在PHP腳本中嵌入C代碼
網(wǎng)址分享:http://m.5511xx.com/article/codsocd.html


咨詢
建站咨詢
