摘要:例如,這里要?jiǎng)?chuàng)建一個(gè)名為的擴(kuò)展現(xiàn)在,在目錄下出現(xiàn)了一個(gè)新建的擴(kuò)展目錄這時(shí),該擴(kuò)展是無(wú)法編譯通過(guò)的,需要先編輯文件才行。
首先需要確定系統(tǒng)中安裝了gcc編譯器,合適版本的bison等,下面是從源碼編譯安裝PHP需要執(zhí)行的基本命令:
# cd php-src # ./buildconf # ./configure --enable-debug --enable-maintainer-zts --enable-cli # make # make install構(gòu)建一個(gè)基本的擴(kuò)展骨架
在PHP擴(kuò)展開發(fā)時(shí),使用ext_skel完成擴(kuò)展的結(jié)構(gòu)骨架創(chuàng)建。
$ ./ext_skel ./ext_skel --extname=module [--proto=file] [--stubs=file] [--xml[=file]] [--skel=dir] [--full-xml] [--no-help] --extname=module 這里的module是要?jiǎng)?chuàng)建的擴(kuò)展名稱 --proto=file 這里的file文件包含了要?jiǎng)?chuàng)建的函數(shù)的原型 --stubs=file generate only function stubs in file --xml generate xml documentation to be added to phpdoc-cvs --skel=dir 創(chuàng)建擴(kuò)展骨架的目錄 --full-xml generate xml documentation for a self-contained extension (not yet implemented) --no-help don"t try to be nice and create comments in the code and helper functions to test if the module compiled
注意: ext_skel命令文件在源文件的ext目錄下。
這里的--extname參數(shù)是要?jiǎng)?chuàng)建的擴(kuò)展名稱,擴(kuò)展名稱為 小寫字母 + 下劃線 組成,并且,
在ext目錄中必須是唯一的。
例如,這里要?jiǎng)?chuàng)建一個(gè)名為ext_demo_1的PHP擴(kuò)展:
/vagrant/ext$ ./ext_skel --extname=ext_demo_1 Creating directory ext_demo_1 Creating basic files: config.m4 config.w32 .svnignore ext_demo_1.c php_ext_demo_1.h CREDITS EXPERIMENTAL tests/001.phpt ext_demo_1.php [done]. To use your new extension, you will have to execute the following steps:
$ cd ..
$ vi ext/extdemo1/config.m4
$ ./buildconf
$ ./configure --[with|enable]-extdemo1
$ make
$ ./php -f ext/extdemo1/extdemo1.php
$ vi ext/extdemo1/extdemo1.c
$ make
Repeat steps 3-6 until you are satisfied with ext/extdemo1/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
現(xiàn)在,在ext目錄下出現(xiàn)了一個(gè)新建的擴(kuò)展目錄ext_demo_1:
/vagrant/ext/ext_demo_1$ ls config.m4 CREDITS ext_demo_1.c php_ext_demo_1.h config.w32 EXPERIMENTAL ext_demo_1.php tests
這時(shí),該擴(kuò)展是無(wú)法編譯通過(guò)的,需要先編輯config.m4文件才行。
配置文件config.m4配置文件config.m4告訴UNIX構(gòu)建系統(tǒng)擴(kuò)展支持的configure選項(xiàng)以及擴(kuò)展需要的額外的庫(kù),
包含哪些源文件等,該文件使用的是GNU的autoconf語(yǔ)法,以dnl開頭的行為注釋,使用中括號(hào)([和])包含的為字符串。
autoconf語(yǔ)法參見 AUTOCONF文檔
PHP_ARG_ENABLE(ext_demo_1, whether to enable ext_demo_1 support, [ --enable-ext_demo_1 Enable ext_demo_1 support]) if test "$PHP_EXT_DEMO_1" != "no"; then PHP_SUBST(EXT_DEMO_1_SHARED_LIBADD) PHP_NEW_EXTENSION(ext_demo_1, ext_demo_1.c, $ext_shared) fi
上述為autoconf的配置文件,第一個(gè)宏PHP_ARG_ENABLE,含有三個(gè)參數(shù):
extdemo1 這是第一個(gè)參數(shù),為./configure建立了名為enable-ext_demo_1的選項(xiàng)
第二個(gè)參數(shù)將會(huì)在./configure命令處理到該擴(kuò)展的配置文件時(shí),顯示該參數(shù)的內(nèi)容
第三個(gè)參數(shù)是./configure命令的幫助,在使用./configure --help的時(shí)候顯示
第二個(gè)宏為PHP_NEW_EXTENSION,該宏聲明了擴(kuò)展的模塊和必須要編譯作為擴(kuò)展一部分的源碼文件。
如果需要多個(gè)源文件,則使用空格分隔,第三個(gè)參數(shù)$ext_shared與調(diào)用
PHP_SUBST(EXT_DEMO_1_SHARED_LIBADD)有關(guān)。
PHP_NEW_EXTENSION(ext_demo_1, ext_demo_1.c, $ext_shared)編譯擴(kuò)展
修改完config.m4文件之后,接下來(lái)編譯PHP和擴(kuò)展。
/vagrant$ ./configure --disable-libxml --enable-ext_demo_1 --disable-dom --disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter --without-pear --prefix=/usr/local/php /vagrant$ make /vagrant$ sudo make install Installing PHP SAPI module: cgi Installing PHP CGI binary: /usr/local/php/bin/ Installing PHP CLI binary: /usr/local/php/bin/ Installing PHP CLI man page: /usr/local/php/man/man1/ Installing build environment: /usr/local/php/lib/php/build/ Installing header files: /usr/local/php/include/php/ Installing helper programs: /usr/local/php/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/man/man1/ page: phpize.1 page: php-config.1 /vagrant/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo/
此時(shí),PHP安裝在了/usr/local/php目錄下,進(jìn)入該目錄,可以看到如下文件:
/usr/local/php$ ls bin include lib man
進(jìn)入/usr/local/php/bin目錄,執(zhí)行以下命令:
/usr/local/php/bin$ ./php --info|grep demo Configure Command => "./configure" "--disable-libxml" "--enable-ext_demo_1" "--disable-dom" "--disable-simplexml" "--disable-xml" "--disable-xmlreader" "--disable-xmlwriter" "--without-pear" "--prefix=/usr/local/php" ext_demo_1 ext_demo_1 support => enabled
可以看到,phpinfo()中擴(kuò)展支持已經(jīng)啟用了,按照上述步驟安裝的擴(kuò)展中包含了一個(gè)測(cè)試擴(kuò)展是否能夠正常工作的函數(shù),該函數(shù)名為confirm_ext_demo_1_compiled(arg),執(zhí)行結(jié)果如下:
/usr/local/php/bin$ ./php -r "echo confirm_ext_demo_1_compiled("mylxsw");" Congratulations! You have successfully modified ext/ext_demo_1/config.m4. Module mylxsw is now compiled into PHP.
可以看到,ext_demo_1擴(kuò)展安裝成功了,關(guān)于擴(kuò)展開發(fā)更多內(nèi)容,請(qǐng)移步 AICODE.CC.
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/21086.html
摘要:簡(jiǎn)介通過(guò)擴(kuò)展,我們可以在代碼中使用一些特定的方法大部分的擴(kuò)展都是用寫的。這個(gè)目錄與我們的擴(kuò)展同名。我們先來(lái)在擴(kuò)展中創(chuàng)建一個(gè)類,使用此類來(lái)渲染。接下來(lái)命令行執(zhí)行以下命令來(lái)編譯擴(kuò)展第一次運(yùn)行以上命令時(shí),會(huì)初始化一些東西。 showImg(https://segmentfault.com/img/remote/1460000018698586); 簡(jiǎn)介: 通過(guò) PHP 擴(kuò)展, 我們可以在 p...
摘要:的機(jī)器學(xué)習(xí)庫(kù)的機(jī)器學(xué)習(xí)庫(kù),包括算法交叉驗(yàn)證神經(jīng)網(wǎng)絡(luò)等內(nèi)容。在即將到來(lái)的大會(huì)上,她將和大家分享在機(jī)器學(xué)習(xí)領(lǐng)域的全新可能。入門總結(jié)入門相關(guān),如安裝配置基本使用等。 基于 Swoole 開發(fā) PHP 擴(kuò)展 Swoole-1.9.7 增加了一個(gè)新特性,可以基于 Swoole 使用 C++ 語(yǔ)言開發(fā)擴(kuò)展模塊,在擴(kuò)展模塊中可以注冊(cè) PHP 內(nèi)置函數(shù)和類?,F(xiàn)在可以基于 Swoole 來(lái)編寫 PHP ...
摘要:我們?yōu)榱颂幚磉@些挑戰(zhàn),提出了一個(gè)新的引用測(cè)試框架當(dāng)然,也是開源的,并且在整個(gè)過(guò)程中節(jié)省了上百萬(wàn)美元。另一方面,被證實(shí)有一些嚴(yán)重的缺點(diǎn)部署困難而且慢。在緩存刷新期間,當(dāng)可用于別的進(jìn)程的已緩存的文件字節(jié)碼在此時(shí)損壞,就會(huì)導(dǎo)致崩潰。 How Badoo saved one million dollars switching to PHP7 我們成功的把我們的應(yīng)用遷移到了php7上面(數(shù)百臺(tái)機(jī)...
摘要:通過(guò)廣泛使用且采用系統(tǒng)的庫(kù),避免了跨站請(qǐng)求偽造其中,用戶能夠被誘騙在你的站點(diǎn)上執(zhí)行某些操作。小結(jié)通過(guò)使用自動(dòng)加載程序所有主流框架的標(biāo)配,避免了遠(yuǎn)程和本地文件包含。另外,對(duì)于伸縮性,重要的是數(shù)據(jù)庫(kù)。 PHP 現(xiàn)在名聲很糟糕,因?yàn)樗?jīng)是可怕的。本文試著回答一些常見的關(guān)于 PHP 的斷言,目的是向非技術(shù)人員解釋,PHP 并不像...
摘要:最近部署上線一個(gè)項(xiàng)目,新的服務(wù)器,在生產(chǎn)環(huán)境安裝配置等各種東西一大堆很麻煩。本文是我學(xué)習(xí)并使用部署項(xiàng)目的一個(gè)記錄。另外我們可以部署不同版本的應(yīng)用,例如,并且互不干擾。之后部署只需要移植鏡像生成容器,就能保證環(huán)境的一致。需要使用三個(gè)鏡像。 最近部署上線一個(gè)項(xiàng)目,新的服務(wù)器,在生產(chǎn)環(huán)境安裝配置nginx、php、mysql、git、composer等各種東西一大堆很麻煩。docker已經(jīng)火...
閱讀 1004·2023-04-25 14:20
閱讀 1881·2021-11-24 10:20
閱讀 3784·2021-11-11 16:55
閱讀 2932·2021-10-14 09:42
閱讀 3479·2019-08-30 15:56
閱讀 1184·2019-08-30 15:55
閱讀 1078·2019-08-30 15:44
閱讀 788·2019-08-29 11:28