php擴(kuò)展開發(fā)

1、下載php7.1。http://us1.php.net/downloads.php#v7.1.20

2、進(jìn)入源碼目錄的ext目錄.

3、執(zhí)行./ext_skel –extname=helloword生成擴(kuò)展骨架

3、修改config.m4文件,該文件中的dnl代表注釋,將以下代碼前的dnl去掉:

dnl PHP_ARG_WITH(helloworld, for helloworld support,
dnl Make sure that the comment is aligned:
dnl [  --with-helloworld             Include helloworld support])

dnl Otherwise use enable:

dnl PHP_ARG_ENABLE(helloworld, whether to enable helloworld support,
dnl Make sure that the comment is aligned:
dnl [  --enable-helloworld           Enable helloworld support])

4、在helloworld.c中找到如下代碼:

PHP_FUNCTION(confirm_helloworld_compiled)
{
    char *arg = NULL;
    size_t arg_len, len;
    zend_string *strg;

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

    strg = strpprintf(0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "helloworld", arg);

    RETURN_STR(strg);
}

在改代碼后面加一個(gè)

PHP_FUNCTION(helloWorld);

5、找到如下代碼:

const zend_function_entry helloworld_functions[] = {
    PHP_FE(confirm_helloworld_compiled, NULL)       /* For testing, remove later. */
    PHP_FE(helloWorld,  NULL)  //添加這一行注冊(cè)自定義函數(shù)
    PHP_FE_END  /* Must be the last line in helloworld_functions[] */
};

6、在helloworld.c文件末尾添加helloworld函數(shù)的代碼實(shí)現(xiàn):

PHP_FUNCTION(helloWorld)
{
    php_printf("Hello World!\n");
    RETURN_TRUE;
}

7、回到源碼目錄編譯安裝:

phpize
./configure(如果想指定php文件配置的話:./configure --with-php-config=/usr/bin/php-config7.1 ,不同的Linux版本位置可能不同)
make
sudo make install

附兩篇參考文檔:
https://blog.csdn.net/u011957758/article/details/72456298

https://www.cnblogs.com/boystar/p/6904795.html

比較詳細(xì)的擴(kuò)展開發(fā)
面向?qū)ο蠓绞?/a>

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容