PHP怎么自定义扩展
发表于:2024-10-12 作者:千家信息网编辑
千家信息网最后更新 2024年10月12日,本篇内容主要讲解"PHP怎么自定义扩展",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"PHP怎么自定义扩展"吧!利用源码工具自动生成扩展目录结构先进入php
千家信息网最后更新 2024年10月12日PHP怎么自定义扩展
本篇内容主要讲解"PHP怎么自定义扩展",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"PHP怎么自定义扩展"吧!
利用源码工具自动生成扩展目录结构
先进入php源码ext目录下执行下面命令
/www/test/php/php/bin/php ext_skel.php --ext helloworldcd helloworld
修改config.m4
配置文件,就是现在写的扩展是否用到外部依赖,就配置--with-hello选项,否则配置--enable-hello
选项,按照自己的需求把注释去掉
dnl If your extension references something external, use 'with': PHP_ARG_WITH([helloworld], [for helloworld support], [AS_HELP_STRING([--with-helloworld], [Include helloworld support])])dnl Otherwise use 'enable':
扩展功能书写
然后vim helloworld.c
进行扩展功能代码书写
先看下模块结构定义
zend_module_entry helloworld_module_entry = { STANDARD_MODULE_HEADER, "helloworld", /* Extension name */ helloworld_functions, /* zend_function_entry */ PHP_MINIT(helloworld), /* PHP_MINIT - Module initialization */ NULL, /* PHP_MSHUTDOWN - Module shutdown */ PHP_RINIT(helloworld), /* PHP_RINIT - Request initialization */ NULL, /* PHP_RSHUTDOWN - Request shutdown */ PHP_MINFO(helloworld), /* PHP_MINFO - Module info */ PHP_HELLOWORLD_VERSION, /* Version */ PHP_MODULE_GLOBALS(pib), NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES_EX};
功能函数名字集合
static const zend_function_entry helloworld_functions[] = { PHP_FE(helloworld_test1, arginfo_helloworld_test1) PHP_FE(helloworld_test2, arginfo_helloworld_test2) PHP_FE_END};
真正的功能函数代码
PHP_FUNCTION(helloworld_test2){ int argc = ZEND_NUM_ARGS(); char *messages = NULL; size_t messages_len = 0; char *context = NULL; size_t context_len = 0; zend_string *retval; ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL Z_PARAM_STRING(messages, messages_len) Z_PARAM_STRING(context, context_len) ZEND_PARSE_PARAMETERS_END(); retval = strpprintf(0, "Hello %s test %s", messages, context); RETURN_STR(retval);}
函数参数定义
ZEND_BEGIN_ARG_INFO(arginfo_helloworld_test2, 0) ZEND_ARG_INFO(0, str)ZEND_END_ARG_INFO()
编译安装
/www/test/php/php/bin/phpize./configure --with-php-config=/www/test/php/php/bin/php-configmake && make install
现在PHP的扩展目录中已经有了helloworld.so
这个文件,在php.ini
中添加上扩展的配置
extension = helloworld.so
然后就可以测试自己写的函数了helloworld_test2()
到此,相信大家对"PHP怎么自定义扩展"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
函数
功能
配置
目录
代码
内容
文件
源码
结构
学习
实用
更深
兴趣
参数
名字
命令
实用性
实际
就是
工具
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
柯镂软件开发上海有限公司
网易版我的世界服务器怎么设置
云服务器股票交易安全么
网络服务器的安装与配置实验心得
淮安云存储服务器好吗
数据库改怎么用
数据库大作业实验心得体会
数据库 事务 提交后 如何回滚
软件开发合同发票
贵州大学网络安全建设学院
3月国产数据库
mstp服务器配置命令
武汉警方开展网络安全整治
幻塔官方服务器是不是互通
CADCAE软件开发
广州市码动未来软件开发有限公司
新华互联网科技全国直营院校
百度时代网络技术是百度百科
ics 服务器设置
服务器进不了bios
科技互联网免费素材图片
一般管理系统共有的数据库表
贵州综合网络安全工程介绍
dns放大攻击的服务器
网络安全老兵事迹
数据库查女生信息怎么查
app服务器怎么访问数据库
网络安全2019热点主题
中电36软件开发
小说网络安全面临的四种威胁