Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP code optimization

I am just wondering what the best way to optimize PHP code is. Is there any way to compress PHP files, or would removing all of the white space improve performance. Any ways to improve performance in PHP files besides just the way you are writing functions?

like image 936
mcbeav Avatar asked Nov 14 '10 06:11

mcbeav


People also ask

How do I optimize my code?

Optimize Program Algorithm For any code, you should always allocate some time to think the right algorithm to use. So, the first task is to select and improve the algorithm which will be frequently used in the code. 2. Avoid Type Conversion Whenever possible, plan to use the same type of variables for processing.

Is PHP getting faster?

The engine has been largely re-written, and PHP is now even quicker than older versions. PHP 8 is a major update of the language and contains many new features and optimizations. You should try to upgrade to the latest stable version quickly - PHP 7.4 is already End of Life.

What do you mean by code optimization?

Definition and Properties Code optimization is any method of code modification to improve code quality and efficiency. A program may be optimized so that it becomes a smaller size, consumes less memory, executes more rapidly, or performs fewer input/output operations.


1 Answers

If you are running on Apache, you can use eAccelerator, which will cache the compiled and optimized bytecode produced by the PHP parser, effectively removing the parsing step after the first hit to each script. On my blog's Wordpress install, this halves (!) the loading time of each page.

If you are trying to optimize the actual running time of your script, you will have to follow the standard wisdom: profile your code, find the bottlenecks, optimize them somehow, and repeat until the script is as fast as you need it to be.

like image 83
cdhowie Avatar answered Oct 13 '22 18:10

cdhowie