PHP Optimization Techniques?

finalheatsmix

New Member
Messages
1
Reaction score
0
Points
0
So I was wondering what are some good techniques to optimize PHP code for the fastest execution. I only technique I know is changing all lines of PHP code to 1 line execution. As far as I know that is one of the worst ways to optimize PHP because you need to make 2 copies of the PHP files.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You should be less concerned with optimization and more concerned with algorithmic efficiency and development practices. As the great Knuth once wrote, "premature optimization is the root of all evil." Optimization is one of the last things to attempt, after your software has matured and the code base is fairly stable. At that point, if your software runs too slowly you profile the code to see where it's running slowest and focus on optimizing that section.

I only technique I know is changing all lines of PHP code to 1 line execution.
What do you mean by this? I have the sneaking suspicion it isn't an optimization.
 

slynn12335

New Member
Messages
1
Reaction score
0
Points
0
You should be less concerned with optimization and more concerned with algorithmic efficiency and development practices.
Exactly. The people developing PHP are already doing their best to optimise processing so it's up to the efficiency of the actual code you are writing. Any glaring performance hits will most likely be a section of your code that's doing a lot more than you need it to without you realising. One quick tip or example (presuming you're using MySQL) is to not SELECT *. Select only what you need (SELECT id,username et cetera).
 

grsubs48

New Member
Messages
12
Reaction score
0
Points
0
is to not SELECT *. Select only what you need (SELECT id,username et cetera).

I'm just browsing some threads here and picking up some useful information. I would have been using SELECT * WHERE field = ? then selecting my fields. I didn't know that you could just select the fields that you required. I don't find the 3k odd pages of the mysql manual very inviting, paticularly, when the only way of reading it is by scrolling thru a pdf file.

Glad to be able to pick up on those little titbits
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I don't find the 3k odd pages of the mysql manual very inviting, paticularly, when the only way of reading it is by scrolling thru a pdf file.
It's not only available as a PDF. The MySQL manual is available in HTML and can be searched using the MySQL site's searches (there's a site wide search and another that searches only the manual) or with Google. There are plenty of other reference sites available online, but if you're doing any sort of development, you need to learn to read the official technical documentation.
 
Top