Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will removing white space and newline characters from PHP make it run faster?

This question refers to performance, not to file size.

I know there are "min" files for javascript and css, but what about optimizing PHP scripts. Of course you will want to keep a copy of the scripts in human readable format. However, for the version running on the production server, will it perform better if it is "optimized" by removing all of the unecessary space and newline / tab characters?

Any benchmarks on this?

like image 968
Chuck Burgess Avatar asked Apr 28 '11 17:04

Chuck Burgess


2 Answers

This has already been discussed some via another question here that you might want to look at: php source code whitespace

Also, while I've never personally made use of it, there appears to be a command "php -w" which removes all whitespace and comments for you, should you want to go that route.

like image 98
JToland Avatar answered Sep 21 '22 21:09

JToland


I would place money on the hypothesis that the tiny amount of extra work that the lexer needs to do in order to skip the whitespace is utterly negligible compared to the actual job of parsing interpreting the rest of the source code.

like image 7
Oliver Charlesworth Avatar answered Sep 21 '22 21:09

Oliver Charlesworth