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

快速開發(fā)一個PHP擴展圖文教程

需求:比如開發(fā)一個叫做 heiyeluren 的擴展,擴展里就一個函數(shù) heiyeluren_test(),輸入一個字符串,函數(shù)返回:Your input string: xxxxx。
要求:了解C/C++編程,熟悉php編程
環(huán)境:下載一份php對應(yīng)版本的源碼,我這里是 php-5.2.6,先正常安裝php,假設(shè)我們的php安裝在 /usr/local/php 目錄,源碼在 /root/soft/php/php-5.2.6/,現(xiàn)在開始!
步驟一:生成擴展框架


cd /root/soft/php/php-5.2.6/ext
./ext_skel --extname=heiyeluren
cd /root/soft/php/php-5.2.6/ext/heiyeluren
vi config.m4
打開文件后去掉 dnl ,獲得下面的信息:
php_ARG_ENABLE(heiyeluren, whether to enable heiyeluren support,
[  --enable-heiyeluren           Enable heiyeluren support])
保存退出.
(圖01)

 

 

第二步:編寫代碼

vi php_heiyeluren.h
找到:php_FUNCTION(confirm_heiyeluren_compiled); ,新增一行:
php_FUNCTION(heiyeluren_test);
保存退出。
(圖02)


vi heiyeluren.c
數(shù)組里增加我們的函數(shù),找到 zend_function_entry heiyeluren_functions[],增加:
php_FE(heiyeluren, NULL)
(圖03)

 

再到 heiyeluren.c 文件最后面增加如下代碼:
php_FUNCTION(heiyeluren_test)
{
    char *arg = NULL;
    int arg_len, len;
    char *strg;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
        return;
    }

    len = spprintf(&strg, 0, "Your input string: %s/n", arg);
    RETURN_STRINGL(strg, len, 0);
}
保存退出。
(圖04)

 

 

 

第三步:編譯安裝

cd /root/soft/php/php-5.2.6/ext/heiyeluren
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make test
make install

現(xiàn)在看看是不是有個 /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/heiyeluren.so
編輯php.ini,把擴展加入進去:
vi /usr/local/php/lib/php.ini
在[php]模塊下增加:
extension = heiyeluren.so
保存退出。
(圖05)

 

注意:如果你不存在擴展文件目錄,或者安裝報錯,那么可以自行建立這個目錄,然后把擴展拷貝到目錄下,然后記得把 php.ini 文件中的 extension_dir 修改為該目錄:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
(圖06)

 

 

第四步:檢查安裝結(jié)果
現(xiàn)在看看模塊加載了沒有:
/usr/local/php/bin/php -m,應(yīng)該會打印出:
[php Modules]
...
heiyeluren
...
[Zend Modules]


然后重啟apache,輸出 phpinfo() ,應(yīng)該能夠看到:
heiyeluren
heiyeluren support enabled
(圖07)

 

看看函數(shù)是否存在并且調(diào)用,在web目錄下建立:heiyeluren.php
<?php
echo "<pre>";
print_r(get_loaded_extensions());
print_r(get_extension_funcs('heiyeluren'));
echo heiyeluren_test('My first php extension');
echo "</pre>";
?>
訪問apache,應(yīng)該能夠看到:
Array
(
    ...
    [33] => heiyeluren
)
Array
(
    [0] => confirm_heiyeluren_compiled
    [1] => heiyeluren_test
)
Your input string: heiyeluren
(圖08)


擴展制作成功!

php技術(shù)快速開發(fā)一個PHP擴展圖文教程,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 九九久久精品 | 亚洲视频在线观 | 18禁止观看免费私人影院 | 国产免费变态视频网址网站 | 日本久久高清视频 | 黄色三级三级三级免费看 | 欧美一区二区在线观看 | 506070老熟肥妇bbwxx视频 4虎最新网址 | 色综合久久网女同蕾丝边 | 精品视频在线播放 | 小寡妇水真多好紧 | 天天插天天舔 | 美女岔开腿露出粉嫩花苞 | 娇小老少配xxxxx | 久久99re66热这里只有精品 | 娇喘嗯嗯 轻点啊视频福利 娇喘高潮教室h | 国产在线AV一区二区香蕉 | 中文字幕s级优女区 | 亚洲中久无码永久在线 | 久久不射视频 | 久久青草免费线观最新 | 亚洲aaaa级特黄毛片 | 天天看片视频免费观看 | 四房播播最新地址 | 国产精品人妻无码免费A片导航 | 日本女人bb| 亚洲欧美色综合影院 | 日本理伦片午夜理伦片 | 草莓视频在线看免费高清观看 | 国产精华av午夜在线观看 | 99国内精品| 国产剧情福利AV一区二区 | 丝袜美腿美女被狂躁在线观看 | 尹人久久大香找蕉综合影院 | 日产亚洲一区二区三区 | YY8848高清私人影院 | 伊人综合在线22 | 亚洲人成网站7777视频 | 香蕉 在线播放 | 久久天天躁狠狠躁夜夜躁 | 国产精品禁18久久久夂久 |