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, but my question is, would clients see a visible speed improvement in page loads and such?
Also, is there a way to compile PHP or something similar?
Source: Tips4all
PHP is compiled into bytecode and runs on something resembling a VM, like Perl, Python and Ruby. It's not really a traditional interpreted language.
ReplyDeleteThere 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.
Edit: Just to make sure it's stated expressly, please read the linked presentation in full. It points out numerous ways to benchmark and profile code and identify bottlenecks using tools like xdebug and xhprof (which is also from Facebook).
Forgo the idea of minifying PHP in favor of using an opcode cache, like PHP Accelerator, or APC.
ReplyDeleteOr something else like memcached
With some rewriting (shorter variable names) you could save a few bytes of memory, but that's also seldomly significant.
ReplyDeleteHowever I do design some of my applications in a way that allows to concatenate include scripts together. With php -w it can be compacted significantly, adding a little speed gain for script startup. On an opcode-enabled server this however only saves a few file mtime checks.
There are PHP compilers... see this previous question for a list; but (unless you're the size of Facebook or are targetting your application to run client-side) they're generally a lot more trouble than they're worth
ReplyDeleteSimple opcode caching will give you more benefit for the effort involved. Or profile your code to identify the bottlenecks, and then optimise it.