PHP Performance Optimization Tips _php Tutorial

Source: Internet
Author: User
About the performance of require, include
Test data:
There is an array, a total of 30,000 pieces of data, 1MB size, I divided into 2 ways to put data to test//sexinsex
1. array.php directly create a new empty PHP file, put the array in
2. Array.txt to save the array after serialize
Test procedure:
Copy content to Clipboard code: for ($i =0; $i <100; $i + +) {
Require (DirName (__file__)./array.php);
}
Results:
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
Require and include speed, the result is not written
Test procedure:
Copy content 97gan to Clipboard code: for ($i =0; $i <100; $i + +) {
$all = Unserialize (file_get_contents (DirName (__file__)./array.txt));
}
Results:
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, the 2-point conclusion of this tutorial comes from the 97xxoo Tutorial Network (www.97xxoo.org)
For a complete tutorial, please click here: http://www.97xxoo.org/article/1/2008/20081124428.shtml
1. When writing some classes or functions, large arrays should not be placed in the program, should be read with the File_get_contents method
2. The way to do the cache, file_get_contents unserialize than require and include faster, such as Sablog and Discuz cache mode is problematic, they are the contents of the database, Program read out and then saved into an array that can be require, the specific program I did not see, var_export can be done, but to achieve, serialize to facilitate the intuitive and much easier
3. With regard to security, PHP directly require the way, although you can add defined () to the top of the head to judge
But File_get_contents method security can do this, put important data in a directory, such as/data/and then put a. htaccess in/data/, write Deny from all, or in the root directory. htaccess the rules for adding a file suffix can be disabled.
Little tricks, just so .....

http://www.bkjia.com/PHPjc/508337.html www.bkjia.com true http://www.bkjia.com/PHPjc/508337.html techarticle about require, include performance test data: There is an array, altogether 30,000 pieces of data, 1MB size, I divided into 2 ways to put the data to test//sexinsex 1. array.php Create a new empty PHP file directly ...

  • 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.