Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a point to minifying PHP?

Tags:

php

minify

I know you can minify PHP, but I'm wondering if there is any point. PHP is an interpreted language so will run a little slower than a compiled language. My question is: would clients see a visible speed improvement in page loads and such if I were to minify my PHP?

Also, is there a way to compile PHP or something similar?

like image 386
Bojangles Avatar asked Nov 02 '10 16:11

Bojangles


People also ask

Are Minifying codes worth it?

Now, because minification removes unnecessary characters from these HTML, CSS, and JS files, the size of these files get smaller. This in turn results in faster downloading and faster rendering of these files. Therefore minification can help improve your website speed.

Why do people minify code?

Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.

Should you minify Javascript?

Minifying strips out all comments, superfluous white space and shortens variable names. It thus reduces download time for your JavaScript files as they are (usually) a lot smaller in filesize. So, yes it does improve performance. The obfuscation shouldn't adversely affect performance.

Should I minify HTML?

Minification means to minimize code (HTML, CSS, JS) and markup in your web pages and script files. This reduces load times and bandwidth usage on websites. Moreover, it improves site speed and accessibility. Additionally, a user can access your website even with a limited data plan.


1 Answers

PHP is compiled into bytecode, which is then interpreted on top of something resembling a VM. Many other scripting languages follow the same general process, including Perl and Ruby. It's not really a traditional interpreted language like, say, BASIC.

There would be no effective speed increase if you attempted to "minify" the source. You would get a major increase by using a bytecode cache like APC.

Facebook introduced a compiler named HipHop that transforms PHP source into C++ code. Rasmus Lerdorf, one of the big PHP guys did a presentation for Digg earlier this year that covers the performance improvements given by HipHop. In short, it's not too much faster than optimizing code and using a bytecode cache. HipHop is overkill for the majority of users.

Facebook also recently unveiled HHVM, a new virtual machine based on their work making HipHop. It's still rather new and it's not clear if it will provide a major performance boost to the general public.

Just to make sure it's stated expressly, please read that presentation in full. It points out numerous ways to benchmark and profile code and identify bottlenecks using tools like xdebug and xhprof, also from Facebook.


2021 Update

HHVM diverged away from vanilla PHP a couple versions ago. PHP 7 and 8 bring a whole bunch of amazing performance improvements that have pretty much closed the gap. You now no longer need to do weird things to get better performance out of PHP!

Minifying PHP source code continues to be useless for performance reasons.

like image 77
Charles Avatar answered Sep 20 '22 15:09

Charles