去掉一下三行的dnl的注释
PHP_ARG_ENABLE(extend_test, whether to enable extend_test support, Make sure that the comment is aligned: [ --enable-extend_test Enable extend_test support])
4、编辑extend_test文件夹下的extend_test.c文件
找到以下方法并修改
PHP_FUNCTION(my_test_function) { char *str = NULL; int argc = ZEND_NUM_ARGS(); size_t str_len; zend_long n; char *result; char *ptr; zend_long result_length; if (zend_parse_parameters(argc TSRMLS_CC, "sl", &str, &str_len, &n) == FAILURE) return; result_length = str_len * n; result = (char *) emalloc(result_length + 1); ptr = result; while (n--) { memcpy(ptr, str, str_len); ptr += str_len; } *ptr = '\0'; RETURN_STRINGL(result, result_length); }
5、生成扩展:
在extend_test文件夹下,运行/home/php/bin/phpize(实际为phpize所在路径)
然后运行./configure --with-php-config=/home/php/bin/php-config(实际为php-config所在路径)
6、编译安装
make make install
7、执行完后会显示扩展安装到了哪个路径下
然后修改php.ini增加扩展信息
extension=extend_test.so
8、测试扩展是否可用
新建test.php文件并将内容编辑为
<?php echo my_test_function('a',5);
保存后用php运行,显示出aaaaa表示扩展成功安装
相关视频教程推荐:《PHP教程》
以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。更多精彩内容大家可以关注Gxl网相关教程栏目!!!
以上就是php中如何使用C语言写扩展的详细内容,更多请关注Gxl网其它相关文章!
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did63002