Cached files. The most commonly used estimation is return array ();
Experiments show that this method is slow. Test the following three files.
1. $ arr. php directly returns an array
<? Php
Return Array
(
& Quot; db_host1 & quot; = & quot; 123,
"Db_host2" => 123,
"Db_host3" => 123,
"Db_host4" => 123,
"Db_host5" => 123,
"Db_host6" => 123,
"Db_host7" => 123,
"Db_host8" => 123,
"Db_host9" => 123,
"Db_host10" => 123,
"Db_host11" => 123,
"Db_host12" => 123,
"Db_host13" => 123,
"Db_host14" => 123,
"Db_host15" => 123,
"Db_host16" = & gt; 123
);
?>
Second, ini. php is the ini file.
<? Php exit;?>
Db_host1 = 123
Db_host2 = 123
Db_host3 = 123
Db_host 4 = 123
Db_host5 = 123
Db_host6 = 123
Db_host7 = 123
Db_host8 = 123
Db_host9 = 123
Db_host10 = 123
Db_host11 = 123
Db_host12 = 123
Db_host13 = 123
Db_host14 = 123
Db_host15 = 123
Db_host16 = 123
Thirdly, str. php is the sorted array.
<? Php
Return
A: 16: {s: 8: "db_host1"; s: 3: "123"; s: 8: "db_host2"; s: 3: "123"; s: 8: "db_host3"; s: 3: "123"; s: 8: "db_host4"; s: 3: "123"; s: 8: "db_host5"; s: 3: "123"; s: 8: "db_host6"; s: 3: "123"; s: 8: "db_host7"; s: 3: "123"; s: 8: "db_host8"; s: 3: "123"; s: 8: "db_host9"; s: 3: "123"; s: 9: "db_host10"; s: 3: "123"; s: 9: "db_host11"; s: 3: "123"; s: 9: "db_host12"; s: 3: "123"; s: 9: "db_host13"; s: 3: "123"; s: 9: "db_host14"; s: 3: "123"; s: 9: "db_host15"; s: 3: "123"; s: 9: "db_host16"; s: 3: "123 ";};
?>
Perform a 10000-containing array test on the three files, respectively.
$ T1 = microtime (true );
$ File1 =./arr. php;
$ File2 =./ini. php;
$ File3 =./str. php;
For ($ I = 0; I I <10000; $ I ++ ){
// $ Arr = require $ file1;
// $ Arr = parse_ini_file ($ file2 );
$ Arr = unserialize (require $ file3 );
}
$ T2 = microtime (true );
Echo $ t2-$ t1;
Result:
Arr. php 5.7820551395416.
Ini. php 5.3364160060883.
Str. php 5.5691919326782
Among them, the fastest ranked is the INI file.
The second is serialization, and the slowest is the direct return array.
Conclusion:
Ini file is good, easy to write (can be considered)
Save the array and use serialization!