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
Open caching method
<?php ini_set('asf.cache_config_enable', 1); /* 开启配置文件缓存 */ ini_set('asf.cache_config_expire', 300); /* 设置缓存多少秒之后过期, 300 seconds by default */
Frame entry way to load php/ ini configuration file
<?php define('APP_PATH', dirname(__DIR__)); /* 缓存 config.ini 文件 */ $app = new Asf\Application(APP_PATH . '/config/config.ini'); $app->run();
Asf\Config\Php Load php configuration file
<?php $conf_php = new Asf\Config\Php(CONFIG_PATH . '/config.db.php');
Asf\Config\Ini Load ini configuration file
<?php $conf_ini = new Asf\Config\Ini(CONFIG_PATH . '/config.redis.ini');
Reading configuration content method
<?php print_r(Asf\Application::getInstance()->getConfig()->toArray()); print_r(Asf\Config::get()->toArray());
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)
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)
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!