PHP performance optimization skills

Source: Internet
Author: User
PHP performance optimization skills, read PHP performance optimization skills, about require, include performance test data: there is an array, a total of 30 thousand pieces of data, 1 MB size, I divided the data into two ways to test // sexinsex1.array. php directly creates an empty php file and places the array in it? Php $ array = array (... 30 thousand array performance of require and include
Test data:
There is an array with a total of 30 thousand pieces of data, 1 MB size, I divided into two ways to test the data // sexinsex
1. create an empty php file in array. php and put the array in.
2. array.txt save the array serialize
Test procedure:
Copy the content to the clipboard code: 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.
Test procedure:
Copy the 97gan content to the clipboard code: 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, draw two conclusions: This tutorial is from the 97xxoo tutorial Network (www.97xxoo.org)
To view the complete tutorial, click: http://www.97xxoo.org/article/1/2008/20081124428.shtml
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. for security, php directly requires ire, although defined () can be added to the top of the head to determine
However, the file_get_contents method can be used in this way to store important data in a directory, such as/data/and then put it in/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 .....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.