php7.4.4扩展开发

编写步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
mkdir /test

cd /test

wget -O https://www.php.net/distributions/php-7.4.4.tar.bz2

tar -jxvf php-7.4.4.tar.bz2


cd php7.4.4/ext

php ext_skel.php --ext my_test

cd my_test

vim my_test.c

增加 自定义函数

PHP_FUNCTION(demo_test){
// ZEND_PARSE_PARAMETERS_NOME();
php_printf("The extension %s is loaded and working!\r\n","my_test");
}

找到以下代码并修改

static const zend_function_entry my_test_functions[] = {
PHP_FE(my_test,NULL)
PHP_FE(my_test_test1, arginfo_my_test_test1)
PHP_FE(my_test_test2, arginfo_my_test_test2)
PHP_FE_END
};

修改完执行以下操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/usr/bin/php74/bin/phpize

./configure --with-php-config=/usr/bin/php74/bin/php-config

make

make test

make install

编辑php.ini

查看php配置文件 /usr/bin/php74/bin/php -i |grep php.ini

增加扩展: extension=my_test.so

查看扩展

/usr/bin/php74/bin/php -m

测试新加函数

/usr/bin/php74/bin/php -r "my_test();"

你是本站第位访客 本站访客数人次
Fork me on GitHub