The following content comes from the network and pro PHP application performance
1. Use require vs require_once
Reference: http://www.laruence.com/2012/09/12/2765.html
Require is faster than require_once due to the high number of operational stat CILS
Made When importing the PHP script. If the file you requested is located within
Directory/var/shared/htdocs/MyApp/models/mymodels/classa. php, the operating system
Will make a stat call within each of the directories before it reaches classa. php. In this
Example, that is a total of six stat cals. While require also issues stat cals, they are fewer
In number. So, the fewer func tion callthere are, the fa ster your code becomes.
Require is faster than require_once because of a large number of stat operations when importing PHP scripts. If you request a file in/var/shared/htdocs/MyApp/models/mymodels/classa. when the file of the PHP address reaches classa. before PHP, the operating system will make a stat call for each directories. Require_once requires six calls. Require also has stat calls, but there are fewer in number. Therefore, it is faster to use it with fewer function calls.
2. Use "comma" instead of "Period"
<?php echo "Hi "."there. "."how are "."you?"; //Slow echo "Hi ","there. ","how are ","you?"; //Faster…slightly
3. traverse the array. foreach is the fastest, while and for are the second.
Episode: Code not optimized
<?php $items = array(1,2,3,4,5,6,7,8,9,10); for($i=0; $i<count($items); $i++) { $x = 10031981 * $i; }
This Code removes count ($ items) to reduce function calls and computation, improving efficiency.
For, foreach, while code, the most efficient foreach, the reason is not found here
<?php $items = array_fill(0, 100000, '12345678910'); $start = microtime(); reset($items); foreach($items as $item) { $x = $item; } echo microtime()-$start;
4. fread is faster when reading small files. file_get_contents is faster when reading large files. The specific size of the file is Median. You can test the file according to the environment.
5. Read the class property and set the class property to public. The fastest way to directly read the class property is not to mention the reason, you know