This article mainly introduces the development of ASF PHP configuration information Resident system memory, has a certain reference value, now share to everyone, the need for friends can refer to
Comparison between traditional MVC and ASF
The traditional MVC framework
Each request will reload the configuration file. Even if the configuration file content is not updated, it will be reloaded once. This is a very bad design. (Open Opcache case, still have the process time of execution)
ASF Framework
The contents of the read to configuration file are saved to the system memory, and the next request goes directly to the memory to read the data. ASF also provides a very simple configuration to implement the Config Cache.
What scenario opens config cache appropriate?
It is recommended that you open it in a Web application scenario, and that later versions may be enabled by default
In CLI, multi-threaded mode is also in effect, but the PHP script is released after each execution
Supported data types are: strings, arrays, integers, Boolean, doubles, floats, null
Flow chart
Turn on caching methods
<?phpini_set (' asf.cache_config_enable ', 1); /* Open config file cache */ini_set (' Asf.cache_config_expire ', 300); /* Set cache number of seconds after expiration, seconds by default */
Frame entry mode load Php/ini configuration file
<?phpdefine (' App_path ', DirName (__dir__));/* Cache config.ini File */$app = new Asf\application (App_path. '/config/config.ini '); $app->run ();
asf\config\php Loading PHP configuration files
<?php$conf_php = new asf\config\php (Config_path. '/config.db.php ');
Asf\config\ini Loading Ini configuration file
<?php$conf_ini = new Asf\config\ini (Config_path. '/config.redis.ini ');
Read configuration content method
<?phpprint_r (Asf\application::getinstance ()->getconfig ()->toarray ());p Rint_r (Asf\Config::get () ToArray ());
Performance testing
In the case of opening Opcache, a simple Config Cache performance test was done, ab-c100-n10000
Configuration items in a configuration file the complexity of the item is connected to the performance index in a linear way.
Turn on cache asf.cache_config_enable = 1
Total transferred: 16109994 byteshtml transferred: 14259994 bytesrequests 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 byteshtml transferred: 14230000 bytesrequests 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
The Cache Config is not based on shared memory, it is based on the PHP process, there is no shared memory lock problem.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!