編寫自己的php擴展函數php程序寫的時間長了,自然對他所提供的功能了如指掌,他所提供的一大堆功能,真是覺得很好用,但有時候會發現php也缺少一些功能,自己總是會產生為php添加一些自定義的 " /> 桃色窝,国产一区二区三区内射高清,亚洲国产中文字幕在线视频综合

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

編寫自己的php擴展函數


編寫自己的php擴展函數php程序寫的時間長了,自然對他所提供的功能了如指掌,他所提供的一大堆功能,真是覺得很好用,但有時候會發現php也缺少一些功能,自己總是會產生為php添加一些自定義的功能的想法。久而久之,終于今天憋不住了,開始動手研究如何添加。

  

下載一個php的源代碼包,這里使用的是php 4.0.5版,解壓后會看到php的根目錄下會有README.EXT_SKEL這樣一個文件,打開詳細閱讀了一下,發現了一個非常好用的工具,這個工具可以幫你構建一個空的php擴展,然后你向里面添加相應的代碼就可以完成你自己的功能擴展了。下面我們就來介紹如何使用這個工具。

  

首先轉移你的目錄到php的目錄下的ext目錄,如果你只需要一個基本的擴展框架的話,執行下面的命令:

./ext_skel --extname=module_name

module_name是你自己可以選擇的擴展模塊的名字,例如我選擇的my_module。執行工具后會自動在ext目錄下建立你選擇的module_name名字的目錄,里面已經生成了相關的代碼,這些代碼中只需要調整config.m4文件中的三行注釋就可以正常的編譯帶這個自定義擴展模塊的php了。在php的根目錄執行下列操作就可以得到。

./buildconf

./configure --enable-module_name

make

  

下面我來演示建立my_module擴展框架的全過程,為了更有效果,我們來完成一個php的擴展功能,在php中調用這個功能可以在web頁面中顯示hello world這個經典單詞。

php目錄下的ext目錄中,執行下面的命令

./ext_skel --extname=my_module

得到反饋結果:

Creating directory my_module

Creating basic files: config.m4 Makefile.in .cvsignore my_module.c php_my_module.h tests/001.phpt my_module.php [done].

  

To use your new extension, you will have to execute the following steps:

1.  $ cd ..

2.  $ vi ext/my_module/config.m4

3.  $ ./buildconf

4.  $ ./configure --[with|enable]-my_module

5.  $ make

6.  $ ./php -f ext/my_module/my_module.php

7.  $ vi ext/my_module/my_module.c

8.  $ make

  

Repeat steps 3-6 until you are satisfied with ext/my_module/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.

  

如果你能看懂上面的東西,那就照著去做。如果不是太明白的話,按照我下面的提示來做也可以。

Cd my_module

首先進入my_module目錄

vi config.m4

使用文本編輯器打開config.m4文件,文件內容大致如下:

dnl $Id$

dnl config.m4 for extension my_module

dnl don't forget to call php_EXTENSION(my_module)

  

dnl Comments in this file start with the string 'dnl'.

dnl Remove where necessary. This file will not work

dnl without editing.

  

dnl If your extension references something external, use with:

  

dnl php_ARG_WITH(my_module, for my_module support,

dnl Make sure that the comment is aligned:

dnl [  --with-my_module             Include my_module support])

  

dnl Otherwise use enable:

  

dnl php_ARG_ENABLE(my_module, whether to enable my_module support,

dnl Make sure that the comment is aligned:

dnl [  --enable-my_module           Enable my_module support])

  

if test "$php_MY_MODULE" != "no"; then

  dnl If you will not be testing anything external, like existence of

  dnl headers, libraries or functions in them, just uncomment the

  dnl following line and you are ready to go.

  dnl Write more examples of tests here...

  php_EXTENSION(my_module, $ext_shared)

Fi

  

根據你自己的選擇將

dnl php_ARG_WITH(my_module, for my_module support,

dnl Make sure that the comment is aligned:

dnl [  --with-my_module             Include my_module support])

修改成

php_ARG_WITH(my_module, for my_module support,

Make sure that the comment is aligned:

[  --with-my_module             Include my_module support])

或者將

dnl php_ARG_ENABLE(my_module, whether to enable my_module support,

dnl Make sure that the comment is aligned:

dnl [  --enable-my_module           Enable my_module support])

修改成

php_ARG_ENABLE(my_module, whether to enable my_module support,

Make sure that the comment is aligned:

[  --enable-my_module           Enable my_module support])

  

一般我會選擇后者,然后保存退出。如果你對vi文本編輯器的操作有困難的話,請參考相應的說明文章,這里就不再詳細描述了。

Vi my_module.c

將文件其中的下列代碼進行修改

/* Every user visible function must have an entry in my_module_functions[].

*/

function_entry my_module_functions[] = {

        php_FE(say_hello,       NULL)  /* ß添加著一行代碼 */

        php_FE(confirm_my_module_compiled,      NULL) /* For testing, remove later. */

        {NULL, NULL, NULL}      /* Must be the last line in my_module_functions[] */

};

  

在文件的最后添加下列代碼

php_FUNCTION(say_hello)

{

        zend_printf("hello world/n");

}

保存文件退出

  

vi php_my_module.h

在文件中php_FUNCTION(confirm_my_module_compiled);一行前面添加下面的代碼

php_FUNCTION(say_hello);

保存文件退出

  

退回到php的根目錄下,執行下面的命令

./buildconf

./configure --enable-my_module

make

  

如果一切順利的話,我們現在已經將擴展模塊my_module編譯到php里面了。我們編寫下面的代碼進行測試

<?

       Say_hello();

?>

保存文件為say_hello.php

php的根目錄下運行

./php 主站蜘蛛池模板: 午夜影视免费 | 亚洲高清视频在线观看 | 久久综合狠狠综合久久综合88 | 精品无码久久久久久动漫 | 国产精一品亚洲二区在线播放 | 99久久婷婷国产麻豆精品电影 | 亚洲涩福利高清在线 | 性xxx欧美| 亚洲人视频在线观看 | 欧美人成在线观看ccc36 | 精品国产国偷自产在线观看 | xx69美国| 国产在线精品一区二区网站免费 | 伊人久久大香线蕉观看 | 少妇无码吹潮久久精品AV | 中文字幕乱码在线人视频 | 帅哥操美女 | 999zyz色资源站在线观看 | 蜜桃传媒星空传媒在线播放 | 国产乱码精品一区二区三区四川 | 国产精品爽爽久久久久久竹菊 | 国产99九九久久无码熟妇 | 无限资源在线看影院免费观看 | 女同志videos最新另 | 白丝美女被狂躁免费漫画 | 顶级少妇AAAAABBBBB片 | 中文字幕亚洲无线码高清不卡 | 我强进了老师身体在线观看 | yellow视频免费观看高清在线 | 人人看人人看 | 国产ZZJJZZJJ视频全免费 | 国产高潮国产高潮久久久久久 | 99久久夜色精品国产亚洲AV卜 | 伊伊人成亚洲综合人网 | 亚洲中文 字幕 国产 综合 | 一区不卡二区卡 | 亚洲爱视频 | 日本久久免费大片 | 久久久久毛片免费观看 | 又紧又大又爽精品一区二区 | 久久亚洲精品成人综合 |