Yaconf is a high-performance configuration management extension, and is an extended application under PHP7 released by PHP core developer Bird Xinchen. The main goal is to simplify reading the project configuration file, separating the configuration file from the project code, and enhancing the readability and maintainability of the configuration file.
According to yaconf developer Xinchen on his blog, the project is a small tool that is handy for the first optimization project after it came to Weibo, itself called weibo_conf. But because weibo_conf is a Weibo extension, there are some other features that are specifically for Weib o Custom-made. Therefore, it is not suitable for direct open source. With the release of PHP7, added a lot of persistent types of support such as Is_immutable_array, so in PHP7 under the re-development of yaconf, open source, convenient for everyone to use.
First of all, what's this about?:
I have seen a lot of projects, with PHP files configured, a config directory may have more than 10 or even dozens of. PHP configuration files, which are all kinds of arrays, but also some of the dictionary files (such as the Chinese/English control) also put in the configuration. This results in a lot of performance for the parsing of the configuration file (admittedly, using the opcache can be better, but there is actually a process to execute).
In addition to PHP, also useful json, YAML, a common feature is that these configurations are relatively poor readability. In addition, they also have to parse the runtime.
Config directory often with the code together, first there will be a security risk (the configuration is often sensitive information), and secondly if the configuration and code belong to a project, which will lead to the configuration of the modification of the code to go the process of the line.
Some resource configuration files, such as Mysql/memcache configuration information, which should be transparent to the development, operation and maintenance directly responsible. But put in the code will cause, operations if you want to initiate some changes, but also to develop with the modification of the configuration file on-line.
So, yaconf is a tool that has been born to solve these problems.
It uses a separate configuration directory (specified in yaconf.directory), not with the code.
It handles all the configuration to be processed when PHP is started, and then the configuration will reside in memory, as the life cycle of PHP survives. Avoid parsing the configuration file each time the request is made.
All of the configuration content is immutable, this can be aided by the Fork of the COW, reduce memory consumption, and in the configuration, almost no need any memory Copy, there will be no unnecessary reference count increase or decrease
Most importantly, after the configuration directory and code separation, you can use a configuration management background, to achieve unified management of the configuration.
It supports (for non-ZTS) configuration change reloading, that is, if the configuration changes (the recommended configuration must use MV, do not use CP), it will reload, do not need to restart (the frequency of detection by Yaconf.check_delay control).
It supports a wide range of configuration types, including 字符串, 数组, 分节, 分节继承
, and can also write PHP constants and environment variables directly in the configuration.
The most important thing is that it's very simple.