栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php7 读取php.ini

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php7 读取php.ini

1.需要实现的细节
  • 在php.ini加上

  • [initest]

  • initest.username=test

  • nitest.userage=99


  • 实现一个initest类 ,实现一个ini_echo方法,打印相关内容

2.initest扩展2.1创建类的扩展:

[root@bogon ext]# cd /usr/local/src/php-7.0.3/ext

[root@bogon ext]# ./ext_skel --extname=initest

2.2 修改配置

[root@bogon ext]# vim initest/config.m4

dnl PHP_ARG_WITH(initest, for initest support,dnl Make sure that the comment is aligned:dnl [  --with-initest             Include initest support])更改为:PHP_ARG_WITH(initest, for initest support,dnl Make sure that the comment is aligned:[  --with-initest             Include initest support])
2.3 实现代码

在php_initest.h中打开全局变量设置块的注释,改成自己相要的变量如下

ZEND_BEGIN_MODULE_GLOBALS(initest)    zend_long  userage;    char      *username;ZEND_END_MODULE_GLOBALS(initest)

在initest.c打开相关注释,并添加相关代码

ZEND_DECLARE_MODULE_GLOBALS(initest)PHP_INI_BEGIN()    STD_PHP_INI_ENTRY("initest.userage","1", PHP_INI_ALL, OnUpdateLong, userage, zend_initest_globals, initest_globals)    STD_PHP_INI_ENTRY("initest.username","username", PHP_INI_ALL, OnUpdateString, username, zend_initest_globals, initest_globals)PHP_INI_END()PHP_MINIT_FUNCTION(initest){    REGISTER_INI_ENTRIES();    return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(initest){        UNREGISTER_INI_ENTRIES();    return SUCCESS;}static void php_initest_init_globals(zend_initest_globals *initest_globals){    //initest_globals->userage = 1;    //initest_globals->username = "testusername";}PHP_FUNCTION(ini_echo){        php_printf("username:%sn",INITEST_G(username));        php_printf("userage:%dn",INITEST_G(userage));}const zend_function_entry initest_functions[] = {    PHP_FE(/confirm/i_initest_compiled,    NULL)           PHP_FE(ini_echo,    NULL)           PHP_FE_END  };
2.4 编译
* [root@bogon hello]# [root@localhost person]# ./configure && make && make install
2.5 扩展安装
[initest]initest.userage=99initest.username=testextension=initest.so
2.6 扩展使用
[root@bogon tests]# cat test.php
- 请尊重本人劳动成功,可以随意转载但保留以下信息 - 作者:岁月经年 - 时间:2016年03月- 来自:www.djhull.com


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/228205.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号