@@ -20,12 +20,21 @@ A well-configured PHP environment is important. To get maximum performance:
2020
2121Beyond environment configuration, there are code-level optimizations that can improve your application's performance:
2222
23+ - Look out for [ algorithm complexity] ( https://en.wikipedia.org/wiki/Time_complexity ) .
24+ Especially give attention to ` foreach ` within ` foreach ` loops but look out for using
25+ [ heavy PHP functions] ( https://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions ) in loops as well.
26+ - [ Speeding up array_merge()] ( https://www.exakat.io/speeding-up-array_merge/ )
27+ - [ Move that foreach() inside the method] ( https://www.exakat.io/move-that-foreach-inside-the-method/ )
28+ - [ Array, classes and anonymous classes memory usage] ( https://www.exakat.io/array-classes-and-anonymous-memory-usage/ )
2329- Use fully qualified function names with leading backslashes to optimize opcache performance.
24- When calling global functions from within a namespace, PHP first searches in the current namespace
25- before falling back to the global namespace. Adding a leading backslash (e.g., ` \count() ` instead of ` count() ` )
26- tells PHP to directly use the global function, avoiding the namespace lookup and improving opcache efficiency.
27- This optimization is best implemented automatically using tools like [ PHP-CS-Fixer] ( https://github.com/FriendsOfPHP/PHP-CS-Fixer )
28- with the ` native_function_invocation ` rule.
30+ When calling [ certain global functions] ( https://github.com/php/php-src/blob/944b6b6bbd6f05ad905f5f4ad07445792bee4027/Zend/zend_compile.c#L4291-L4353 )
31+ from within a namespace, PHP first searches in the current namespace before falling back to the global namespace.
32+ Adding a leading backslash (e.g., ` \count() ` instead of ` count() ` ) tells PHP to directly use the global function,
33+ avoiding the namespace lookup and improving opcache efficiency. This optimization is best implemented automatically
34+ using tools like [ PHP-CS-Fixer] ( https://github.com/FriendsOfPHP/PHP-CS-Fixer ) with the ` native_function_invocation ` rule.
35+
36+ The above optimizations would give you a significant performance boost only if the code in question is executed
37+ frequently. That is usually the case for big loops or batch processing.
2938
3039## Using caching techniques <span id =" using-caching-techniques " ></span >
3140
0 commit comments