Home > Backend Development > PHP Tutorial > Asf PHP development configuration information resident in system memory

Asf PHP development configuration information resident in system memory

藏色散人
Release: 2023-04-07 20:36:01
forward
2269 people have browsed it

Comparison between traditional MVC and Asf

Traditional MVC framework

The configuration file will be reloaded with each request. Even if the configuration file content has not been updated, it will be reloaded. This is a very bad design. (When Opcache is turned on, there is still execution time)

Asf framework

The content of the read configuration file is saved to the system memory, and the next request goes directly Read data from memory. Asf also provides a very simple configuration implementation Config Cache.

In what scenarios is it appropriate to enable Config Cache?

● It is recommended to enable it in web application scenarios. Later versions may enable it by default

●● Enabling it in CLI and multi-threaded mode also takes effect, except that the PHP script is released every time it is executed.

● Supported data types are: strings, arrays, integers, boolean, doubles, floats, null

Flowchart

Asf PHP development configuration information resident in system memory

Open caching method

<?php
ini_set(&#39;asf.cache_config_enable&#39;, 1); /* 开启配置文件缓存 */
ini_set(&#39;asf.cache_config_expire&#39;, 300); /* 设置缓存多少秒之后过期, 300 seconds by default */
Copy after login

Frame entry way to load php/ ini configuration file

<?php
define(&#39;APP_PATH&#39;, dirname(__DIR__));
/* 缓存 config.ini 文件 */
$app = new Asf\Application(APP_PATH . &#39;/config/config.ini&#39;);
$app->run();
Copy after login

Asf\Config\Php Load php configuration file

<?php
$conf_php =  new Asf\Config\Php(CONFIG_PATH . &#39;/config.db.php&#39;);
Copy after login

Asf\Config\Ini Load ini configuration file

<?php
$conf_ini =  new Asf\Config\Ini(CONFIG_PATH . &#39;/config.redis.ini&#39;);
Copy after login

Reading configuration content method

<?php
print_r(Asf\Application::getInstance()->getConfig()->toArray());
print_r(Asf\Config::get()->toArray());
Copy after login

Performance test

● With Opcache enabled, simply do a Config Cache performance test, ab -c100 -n10000

● There is a direct relationship between the complexity of configuration items in the configuration file and performance indicators

Enable cache asf.cache_config_enable = 1

Total transferred:      16109994 bytes
HTML transferred:       14259994 bytes
Requests per second:    6859.01 [#/sec] (mean)
Time per request:       14.579 [ms] (mean)
Time per request:       0.146 [ms] (mean, across all concurrent requests)
Copy after login

No cache

Total transferred:      16080000 bytes
HTML transferred:       14230000 bytes
Requests per second:    6398.22 [#/sec] (mean)
Time per request:       15.629 [ms] (mean)
Time per request:       0.156 [ms] (mean, across all concurrent requests)
Copy after login

Tips

Cache Config is not based on shared memory, but based on the PHP process Yo, there will be no problem with shared memory locks.

Recommended: "PHP Tutorial"

The above is the detailed content of Asf PHP development configuration information resident in system memory. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template