Test data:
There is an array with a total of 30 thousand pieces of data, 1 MB. I divided it into two ways to test the data.
1. Create an empty PHP file in array. php and put the array in. <? PHP $ array = array (... 30 thousand array ...); ?>
2. array.txt Save the array serialize
 
 
 
  
   
   1 2 3
   |  
   for ($i=0 ;$i<100; $i++){ require(dirname(__FILE__).'/array.php'); } |  
  
 
  
 
Result:
Page execution time: 12.8904 seconds
Page execution time: 12.8863 seconds
Page execution time: 12.8942 seconds
Page execution time: 12.8992 seconds
Page execution time: 12.9013 seconds
If require and include are the same speed, the results will not be written.
 
 
 
  
   
   1 2 3
   |  
   for ($i=0 ;$i<100; $i++){ $all = unserialize(file_get_contents(dirname(__FILE__).'/array.txt')); } |  
  
 
  
 
Result:
Page execution time: 3.7988 seconds
Page execution time: 3.8125 seconds
Page execution time: 3.8118 seconds
Page execution time: 3.8062 seconds
Page execution time: 3.8311 seconds
 
Therefore, two conclusions are drawn.
1. When writing some classes or functions, do not place large arrays in the program. You should use the file_get_contents method to read them.
2. the cache method is file_get_contents and then unserialize is faster than require and include. For example, the cache methods of sablog and discuz are problematic. They refer to the content in the database, after the program is read and saved as an array that can be require, the specific program can be done without looking at it again, var_export can be done, but it is much easier to implement serialize.
3. regarding security, PHP directly uses the require method. Although defined () can be added to the top of the head to determine the security, the file_get_contents method can do so by storing important data in a directory, for example,/data. htaccess, write deny from all, or put it in the root directory. rules for adding file suffixes to htaccess are not allowed.
TIPS: Just so .....