A high-performance configuration management extension in PHP yaconf detailed

Source: Internet
Author: User

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?:

    1. 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).

    2. 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.

    3. 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.

    4. 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.

    1. It uses a separate configuration directory (specified in yaconf.directory), not with the code.

    2. 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.

    3. 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

    4. Most importantly, after the configuration directory and code separation, you can use a configuration management background, to achieve unified management of the configuration.

    5. 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).

    6. It supports a wide range of configuration types, including 字符串, 数组, 分节, 分节继承 , and can also write PHP constants and environment variables directly in the configuration.

    7. The most important thing is that it's very simple.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.