Yaconf - Yet Another Configurations Container

Overview

Yaconf - Yet Another Configurations Container

Build Status Build status Build Status

A PHP Persistent Configurations Container

Requirement

  • PHP 7+

Introduction

Yaconf is a configurations container, it parses ini files, store the result in PHP when PHP is started, configurations live in the whole PHP lifecycle, which makes it very fast.

Features

  • Fast, Light
  • Zero-copy while accesses configurations
  • Support sections, sections inheritance
  • Configurations reload automatically after changed

Install

Compile Yaconf in Linux

Yaconf is an PECL extension, thus you can simply install it by:

$pecl install yaconf

Or you can compile it by your self:

$ /path/to/php7/bin/phpize
$ ./configure --with-php-config=/path/to/php7/bin/php-config
$ make && make install

Runtime configuration

  • yaconf.directory
  Path to directory which all ini configuration files are placed in
  • yaconf.check_delay
  In which interval Yaconf will detect ini file's change(by directory's mtime),
  if it is set to zero, you have to restart php to reloading configurations.

APIs

mixed Yaconf::get(string $name, mixed $default = NULL)
bool  Yaconf::has(string $name)

Example

Directory

Assuming we place all configurations files in /tmp/yaconf/, thus we added this into php.ini

yaconf.directory=/tmp/yaconf

INI Files

Assuming there are two files in /tmp/yaconf

foo.ini

name="yaconf"                  ;string
year=2015                      ;number
features[]="fast"              ;map
features.1="light"
features.plus="zero-copy"
features.constant=PHP_VERSION  ;PHP constants
features.env=${HOME}           ;Enviorment variables

and bar.ini

[base]
parent="yaconf"
children="NULL"

[children:base]               ;inherit from section "base"
children="set"

Run

lets retrieve the configurations from Yaconf

foo.ini
string(6) "yaconf" ["year"]=> string(4) "2015" ["features"]=> array(5) { [0]=> string(4) "fast" [1]=> string(5) "light" ["plus"]=> string(9) "zero-copy" ["constant"]=> string(9) "7.0.0-dev" ["env"] => string(16) "/home/huixinchen" } } */">
php7 -r 'var_dump(Yaconf::get("foo"));'
/*
array(3) {
  ["name"]=>
  string(6) "yaconf"
  ["year"]=>
  string(4) "2015"
  ["features"]=>
  array(5) {
    [0]=>
    string(4) "fast"
    [1]=>
    string(5) "light"
    ["plus"]=>
    string(9) "zero-copy"
    ["constant"]=>
    string(9) "7.0.0-dev"
    ["env"] =>
    string(16) "/home/huixinchen"
  }
}
*/

As you can see, Yaconf supports string, map(array), ini, env variable and PHP constants.

You can also access configurations like this:

php7 -r 'var_dump(Yaconf::get("foo.name"));'
//string(6) "yaconf"

php7 -r 'var_dump(Yaconf::get("foo.features.1"));'
//string(5) "light"

php7 -r 'var_dump(Yaconf::get("foo.features")["plus"]);'
//string(9) "zero-copy"
bar.ini

Now let's see the sections and sections inheritance:

array(2) { ["parent"]=> string(6) "yaconf" ["children"]=> string(4) "NULL" } ["children"]=> array(2) { ["parent"]=> string(6) "yaconf" ["children"]=> string(3) "set" } } */">
php7 -r 'var_dump(Yaconf::get("bar"));'
/*
array(2) {
  ["base"]=>
  array(2) {
    ["parent"]=>
    string(6) "yaconf"
    ["children"]=>
    string(4) "NULL"
  }
  ["children"]=>
  array(2) {
    ["parent"]=>
    string(6) "yaconf"
    ["children"]=>
    string(3) "set"
  }
}
*/

Children section has inherited values in base sections, and children is able to override the values they want.

Comments
  • Segmentation fault      $php_fpm_BIN --daemonize $php_opts

    Segmentation fault $php_fpm_BIN --daemonize $php_opts

    安装好扩展并开启扩展,重启fpm进程时遇到错误:

    Starting php-fpm /etc/init.d/php-fpm7: line 53: 17443 Segmentation fault      $php_fpm_BIN --daemonize $php_opts
    

    我使用php7.0.x,请帮助修复这个问题。

    opened by tianmingxing 14
  •  配置yaconf.directory 后segmentation fault

    配置yaconf.directory 后segmentation fault

    ➜ tail -f -n 10 etc/php.ini [redis] extension="redis.so"

    [ast] extension=ast.so

    [Yaconf] extension=yaconf.so yaconf.directory="/home/www/yaconf" yaconf.check_delay=1

    ➜ php -v [1] 13598 segmentation fault php -v

    // ------- 环境 Mac Pro - EI Captian 10.11.5 PHP 7.0.5 (cli) (built: Apr 11 2016 02:07:04) ( NTS DEBUG ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

    Linux 环境是正常的 CentOS 7.0 PHP 7.0.6 (cli) (built: May 17 2016 17:11:07) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

    //// ----- Mac 开发机 多开了个 DEBUG

    opened by xinhaiz 7
  • yaconf 内存溢出bug

    yaconf 内存溢出bug

    php 版本 7.0.7 yaconf 版本 1.0.2

    运行下面的代码 PHP 进程的内存会一直增加。

    while(true){ $acc = yaconf::get('topic.time_line'); array_walk_recursive($acc, function ($item) { }); var_dump(Memory_get_usage()); }

    这样内存会一直增长。

    opened by WLWL 6
  • PHP7.2.10 设置目录无法启动

    PHP7.2.10 设置目录无法启动

    如果为directory设置一个不存在的目录,PHP可以启动,如果一个存在的目录,不管是空目录还是有INI文件,PHP都启动不起来, 7.1.x没发现这问题。我是在cli模式下测试的

    windows10 64

    PHP 7.2.10 (cli) (built: Sep 13 2018 00:47:25) ( NTS MSVC15 (Visual C++ 2017) x64 )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    

    php配置

    extension=php_yaconf
    yaconf.directory = "D:/php/test"
    yaconf.check_delay=5
    
    opened by zszyue 5
  • 请问配置引用应该怎么做?

    请问配置引用应该怎么做?

    比如我有一个域名的配置, env.ini

    domain=xxxx.weibo.com
    

    这时如果我想在同一个配置文件或别的配置文件中(不是在PHP代码中)引用这个domain值,要怎么做呢?因为我会有很多不经常变的配置比如,播放地址、管理后台地址什么的。虽然也可以一遍一遍的写,但在一台多人使用的开发机上配置不同域名的开发环境就比较麻烦了。

    希望鸟哥能给指条路

    opened by lovelock 5
  • PHP8.1安装Yaconf1.1.1导致数据解析错误

    PHP8.1安装Yaconf1.1.1导致数据解析错误

    image

    var_dump(
        Yaconf::get('dicRegexp'),
        Yaconf::get('adminProduct'),
        Yaconf::get('storeTable')
    );
    

    如题,我的项目配置文件:https://github.com/letwang/HookPHP/tree/master/conf

    现在每个ini文件无法根据key正确查找到内容,无论我更换什么key,输出的结果都是一样的。

    opened by letwang 4
  • PHP73 编译扩展时出问题,pecl 装也会有这个错误

    PHP73 编译扩展时出问题,pecl 装也会有这个错误

    make的时候出现这个异常了

    mkdir .libs
     cc -I. -I/app/yaconf-yaconf-1.0.6 -DPHP_ATOM_INC -I/app/yaconf-yaconf-1.0.6/include -I/app/yaconf-yaconf-1.0.6/main -I/app/yaconf-yaconf-1.0.6 -I/usr/include/php7 -I/usr/include/php7/main -I/usr/include/php7/TSRM -I/usr/include/php7/Zend -I/usr/include/php7/ext -I/usr/include/php7/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /app/yaconf-yaconf-1.0.6/yaconf.c  -fPIC -DPIC -o .libs/yaconf.o
    /app/yaconf-yaconf-1.0.6/yaconf.c: In function 'php_yaconf_hash_init':
    /app/yaconf-yaconf-1.0.6/yaconf.c:92:15: error: lvalue required as left operand of assignment
      GC_FLAGS(ht) |= IS_ARRAY_IMMUTABLE;
                   ^~
    /app/yaconf-yaconf-1.0.6/yaconf.c:93:18: error: lvalue required as left operand of assignment
      GC_REFCOUNT(ht) = 2;
                      ^
    /app/yaconf-yaconf-1.0.6/yaconf.c:98:23: error: 'IS_TYPE_COPYABLE' undeclared (first use in this function)
      Z_TYPE_FLAGS_P(zv) = IS_TYPE_COPYABLE;
                           ^~~~~~~~~~~~~~~~
    /app/yaconf-yaconf-1.0.6/yaconf.c:98:23: note: each undeclared identifier is reported only once for each function it appears in
    /app/yaconf-yaconf-1.0.6/yaconf.c: In function 'php_yaconf_str_persistent':
    /app/yaconf-yaconf-1.0.6/yaconf.c:144:16: error: lvalue required as left operand of assignment
      GC_FLAGS(key) |= IS_STR_INTERNED | IS_STR_PERMANENT;
                    ^~
    /app/yaconf-yaconf-1.0.6/yaconf.c: In function 'php_yaconf_zval_persistent':
    /app/yaconf-yaconf-1.0.6/yaconf.c:166:8: error: 'IS_CONSTANT' undeclared (first use in this function)
       case IS_CONSTANT:
            ^~~~~~~~~~~
    make: *** [Makefile:194: yaconf.lo] Error 1
    
    opened by m9rco 4
  • php 7.3.4 make error

    php 7.3.4 make error

    鸟哥,今天编译时发生下面这个错误 /home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c: In function ‘php_yaconf_hash_init’: /home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:90:15: error: lvalue required as left operand of assignment GC_FLAGS(ht) |= IS_ARRAY_IMMUTABLE; ^~/home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:91:15: error: lvalue required as left operand of assignment GC_FLAGS(ht) |= HASH_FLAG_STATIC_KEYS; ^~/home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:95:19: error: ‘HASH_FLAG_APPLY_PROTECTION’ undeclared (first use in this function); did you mean‘_SC_MEMORY_PROTECTION’? GC_FLAGS(ht) &= ~HASH_FLAG_APPLY_PROTECTION; ^~~~~~~~~~~~~~~~~~~~~~~~~~ _SC_MEMORY_PROTECTION/home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:95:19: note: each undeclared identifier is reported only once for each function it appears in /home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:98:18: error: lvalue required as left operand of assignment GC_REFCOUNT(ht) = 2; ^ /home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:103:23: error: ‘IS_TYPE_COPYABLE’undeclared (first use in this function); did you mean ‘Z_OPT_COPYABLE’? Z_TYPE_FLAGS_P(zv) = IS_TYPE_COPYABLE; ^~~~~~~~~~~~~~~~ Z_OPT_COPYABLE/home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c: In function ‘php_yaconf_str_persistent’: /home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:149:16: error: lvalue required as left operand of assignment GC_FLAGS(key) |= IS_STR_INTERNED | IS_STR_PERMANENT; ^~/home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c: In function ‘php_yaconf_zval_persistent’: /home/tangchao/Downloads/yaconf-yaconf-1.0.7/yaconf.c:171:8: error: ‘IS_CONSTANT’ undeclared(first use in this function); did you mean ‘RT_CONSTANT’? case IS_CONSTANT: ^~~~~~~~~~~ RT_CONSTANTmake: *** [Makefile:194:yaconf.lo] 错误 1

    opened by tangchao1992 3
  • php-7.3.1编辑错误

    php-7.3.1编辑错误

    /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c: In function ‘php_yaconf_hash_init’: /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:90:15: error: lvalue required as left operand of assignment GC_FLAGS(ht) |= IS_ARRAY_IMMUTABLE; ^~ /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:91:15: error: lvalue required as left operand of assignment GC_FLAGS(ht) |= HASH_FLAG_STATIC_KEYS; ^~ /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:95:19: error: ‘HASH_FLAG_APPLY_PROTECTION’ undeclared (first use in this function); did you mean ‘_SC_MEMORY_PROTECTION’? GC_FLAGS(ht) &= ~HASH_FLAG_APPLY_PROTECTION; ^~~~~~~~~~~~~~~~~~~~~~~~~~ _SC_MEMORY_PROTECTION /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:95:19: note: each undeclared identifier is reported only once for each function it appears in /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:98:18: error: lvalue required as left operand of assignment GC_REFCOUNT(ht) = 2; ^ /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:103:23: error: ‘IS_TYPE_COPYABLE’ undeclared (first use in this function); did you mean ‘Z_OPT_COPYABLE’? Z_TYPE_FLAGS_P(zv) = IS_TYPE_COPYABLE; ^~~~~~~~~~~~~~~~ Z_OPT_COPYABLE /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c: In function ‘php_yaconf_str_persistent’: /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:149:16: error: lvalue required as left operand of assignment GC_FLAGS(key) |= IS_STR_INTERNED | IS_STR_PERMANENT; ^~ /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c: In function ‘php_yaconf_zval_persistent’: /usr/local/src/php-7.3.1/ext/yaconf/yaconf.c:171:8: error: ‘IS_CONSTANT’ undeclared (first use in this function); did you mean ‘RT_CONSTANT’? case IS_CONSTANT: ^~~~~~~~~~~ RT_CONSTANT Makefile:194: recipe for target 'yaconf.lo' failed make: *** [yaconf.lo] Error 1

    opened by infatu8 3
  • yaconf在php7.3下安装失败

    yaconf在php7.3下安装失败

    /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c: In function ‘php_yaconf_hash_init’: /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c:92:15: error: lvalue required as left operand of assignment GC_FLAGS(ht) |= IS_ARRAY_IMMUTABLE; ^ /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c:93:18: error: lvalue required as left operand of assignment GC_REFCOUNT(ht) = 2; ^ /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c:98:23: error: ‘IS_TYPE_COPYABLE’ undeclared (first use in this function) Z_TYPE_FLAGS_P(zv) = IS_TYPE_COPYABLE; ^ /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c:98:23: note: each undeclared identifier is reported only once for each function it appears in /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c: In function ‘php_yaconf_str_persistent’: /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c:144:16: error: lvalue required as left operand of assignment GC_FLAGS(key) |= IS_STR_INTERNED | IS_STR_PERMANENT; ^ /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c: In function ‘php_yaconf_zval_persistent’: /home/webb.m/source/yaconf-yaconf-1.0.6/yaconf.c:166:8: error: ‘IS_CONSTANT’ undeclared (first use in this function) case IS_CONSTANT: ^ make: *** [yaconf.lo] Error 1

    我用的php7.3 系统是centos centos-release-7-5.1804.el7.centos.x86_64 我使用了pecl 和源码安装都出现了同样的问题。

    opened by Justin0530 3
  • 能否支持数字类型输出?

    能否支持数字类型输出?

    [redis] default.host=127.0.0.1 default.port=6379 default.timeout=1 default.reserved=NULL default.interval=100 default.auth=123456

    上述 比如 port 配置成了数字6379,取出来的是字符串6379,这样在PHP7强类型情况下

    declare(strict_types=1);
    

    代码就会报错

    $redis->connect(
                APP_CONFIG['redis'][$db]['host'],
                APP_CONFIG['redis'][$db]['port'],
                APP_CONFIG['redis'][$db]['timeout'],
                APP_CONFIG['redis'][$db]['reserved'],
                APP_CONFIG['redis'][$db]['interval']
            );
    
    Fatal error: Uncaught TypeError: Redis::connect() expects parameter 2 to be int, string given
    
    
    opened by letwang 2
  • Support multi-level directory  &&   fix sections coredump bug

    Support multi-level directory && fix sections coredump bug

    1、Support multi-level directory configuration: yaconf.directory = /tmp/yaconf/ ini file path: /tmp/yaconf/test/foo.ini use age: php7 -r 'var_dump(Yaconf::get("test/foo"));'

    2、fix sections coredump bug eg:foo.ini

    name=1 [student:name] test=2

    3、configuration add yaconf.check_type if it is set to zero (default) will detect ini file's change by directory's mtime , otherwise will detect each file's mtime.

    opened by destinyac 0
Owner
Xinchen Hui
PHP Stylite
Xinchen Hui
Yet Another LINQ to Objects for PHP [Simplified BSD]

YaLinqo: Yet Another LINQ to Objects for PHP Online documentation GitHub repository Features The most complete port of .NET LINQ to PHP, with many add

Alexander Prokhorov 436 Jan 3, 2023
YAPS - Yet Another PHP Shell

YAPS - Yet Another PHP Shell Yeah, I know, I know... But that's it. =) As the name reveals, this is yet another PHP reverse shell, one more among hund

Nicholas Ferreira 60 Dec 14, 2022
Yet Another Swoole Debugger

English | 中文 yasd Yet Another Swoole Debugger. document How to use it build You'll need to install the Boost library first. macOS: brew install boost

Swoole Project 319 Dec 25, 2022
Yet another Value Object Library (YAVOL)

Yet Another DDD Library Value object This library is a foundation in order to implement the Value Object pattern. It helps you to introduce some DDD s

YADDDL 3 Nov 17, 2022
Simple and minimal yet another PHP 7 Framework

DemirApp Minimal PHP Framework Introduction Simple and minimal yet another PHP 7 Framework Features Simple routing Simple container (Dependency Inject

yidemir 12 Sep 19, 2022
Yet another PHP Microframework.

ρ Yet another PHP Microframework. The premise of this framework is to be backwards-compatible (PHP <= 5.6) with powerful utilities (Like caching and l

null 0 Apr 6, 2022
Here you have yet another framework for writing RESTful web services in PHP

PHP-Rocker Here you have yet another framework for writing RESTful web services in PHP, jay! What sets this framework apart from many of the others is

Victor Jonsson 43 May 19, 2022
Jump is yet another self-hosted startpage for your server designed to be simple, stylish, fast and secure.

Jump Jump is yet another self-hosted startpage for your server designed to be simple, stylish, fast and secure. Features Fast, easy to deploy, secure

Dale Davies 309 Dec 27, 2022
Yet another asynchronous permission management plugin for PocketMine-MP.

GroupsAPI Yet another asynchronous permission management plugin for PocketMine-MP. Features Developer-friendly API Temporary rank/group support Multip

null 19 Nov 28, 2022
📷 Yet another photo management app for Nextcloud

Memories ?? Yet another photo management app for Nextcloud How is this different? ?? Photo and Video Timeline: Sorts photos by date taken, parsed from

Varun Patil 322 Jan 8, 2023
What do developers do on holidays? Right! Yet another sudoku.

yasu This is a project that happened to obsess the contributors on a greek island in the summer of 2022: figure out how to generate and solve sudoku b

null 2 Sep 18, 2022
Utility that helps you switch git configurations with ease.

git-profile Utility that helps you switch git configurations with ease Preface It is possible that you have multiple git configurations. For example:

Zeeshan Ahmad 240 Jul 18, 2022
A script to help setup Laravel project with common packages and configurations

About Snap Snap allow developer to create scaffold Laravel project. Installation Clone this repository in your user home directory. cd ~ git clone htt

Nasrul Hazim Bin Mohamad 3 Jan 4, 2022
Registry manager for Laravel 5. An alternative for managing application configurations and settings.

Registry manager for Laravel 5. An alternative for managing application configurations and settings. Now with the magic of caching, so no more database calls to simply get site setting.

Daniel Stainback 22 Sep 28, 2020
An artisan command for using multiple environment configurations in Laravel 5

Laravel 5 env An artisan command for managing multiple .env of your Laravel 5 app. Installation Copy EnvCommand.php to app/Console/Commands/ of your L

Tommy Ku 18 Nov 29, 2022
A package that allows you to generate simple and fast Docker configurations for your Laravel application!

A package that allows you to generate simple and fast Docker configurations for your Laravel application!

Lucas Nepomuceno 3 Oct 8, 2022
Easy Coding Standard configurations for Craft CMS projects.

Easy Coding Standard config for Craft CMs This package provides Easy Coding Standard configurations for Craft CMS plugins and projects. In general, we

Craft CMS 10 Dec 18, 2022
Fluent Interface for Laravel Backpack - Define resources once and get all CRUD configurations ready!

CRUD Resource for Laravel Backpack This package allows creating CRUD panels for Backpack for Laravel administration panel using fluent field definitio

FigLab 8 Nov 20, 2022
A small PHP dependency injection container

Pimple Caution! Pimple is now closed for changes. No new features will be added and no cosmetic changes will be accepted either. The only accepted cha

Silex 2.6k Dec 29, 2022
The dependency injection container for humans

layout home PHP-DI is a dependency injection container meant to be practical, powerful, and framework-agnostic. Read more on the website: php-di.org G

null 2.4k Jan 4, 2023