您好,欢迎访问一九零五行业门户网

Asf PHP 开发之配置信息常驻系统内存

这篇文章主要介绍了关于asf php 开发之配置信息常驻系统内存,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
传统mvc 与 asf 比较传统的mvc框架每次请求都会去重新加载配置文件。即使配置文件内容没有更新, 也会去重新加载一次。这是一个很不好的设计。(开启opcache情况下, 还是有执行的过程时间)
asf框架读取到配置文件的内容保存到系统内存, 下一次请求直接去内存读取数据。asf 也提供非常简单的配置实现 config cache。
什么场景下开启config cache合适?建议在web应用场景下都开启吧, 后面版本可能会默认启用
在cli、多线程模式下开启同样生效, 只是php脚本每次执行完就释放了
支持数据类型有: strings, arrays, integers, boolean, doubles, floats, null
流程图
开启缓存方法<?phpini_set('asf.cache_config_enable', 1); /* 开启配置文件缓存 */ini_set('asf.cache_config_expire', 300); /* 设置缓存多少秒之后过期, 300 seconds by default */
框架入口方式加载php/ini配置文件<?phpdefine('app_path', dirname(__dir__));/* 缓存 config.ini 文件 */$app = new asf\application(app_path . '/config/config.ini');$app->run();
asf\config\php 加载php配置文件<?php$conf_php = new asf\config\php(config_path . '/config.db.php');
asf\config\ini 加载ini配置文件<?php$conf_ini = new asf\config\ini(config_path . '/config.redis.ini');
读取配置内容方法<?phpprint_r(asf\application::getinstance()->getconfig()->toarray());print_r(asf\config::get()->toarray());
性能测试在开启 opcache 情况下, 简单做了一个 config cache 性能测试, ab -c100 -n10000
配置文件中配置项复杂程度与性能指标是有直线联系的哟
开启缓存 asf.cache_config_enable = 1total transferred:      16109994 byteshtml transferred:       14259994 bytesrequests per second:    6859.01 [#/sec] (mean)time per request:       14.579 [ms] (mean)time per request:       0.146 [ms] (mean, across all concurrent requests)
无缓存total transferred:      16080000 byteshtml transferred:       14230000 bytesrequests per second:    6398.22 [#/sec] (mean)time per request:       15.629 [ms] (mean)time per request:       0.156 [ms] (mean, across all concurrent requests)
提示cache config 不是基于共享内存的, 是基于 php 进程的哟, 不会有共享内存锁的问题。
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注!
相关推荐:
nginx负载调度器+双tomcat负载及会话共享+mysql后端数据库
thinkphp5.0 linux apache/nginx重写url配置
使用cronolog切割nginx访问日志,定时清理旧日志
以上就是asf php 开发之配置信息常驻系统内存的详细内容。
其它类似信息

推荐信息