1

This maybe a very stupid question as PHP is server side programming

But if minifying CSS and minifying Javascript (although they are client side) is a good thing to do to optimise for speed, is there such a thing as minifying PHP and would it have any performance gains on the server?

..or would this simply be a waste of time and effort?

Arth
  • 12,789
  • 5
  • 37
  • 69
Liam Sorsby
  • 2,912
  • 3
  • 28
  • 51
  • 2
    I shouldn't see why not, however you'll have a "whale of a time" editing it afterwards if you need to debug/modify and will constantly be running with 2 copies. – Funk Forty Niner Sep 16 '13 at 18:54
  • @Fred-ii- hello again. yes i thought of that after however i was just curious as i know that css and javascript are minified due to the clients machine downloading the code which wouldn't be the case with php it would more be the script time and the html output however i meant more on the server side of things would it increase performance? – Liam Sorsby Sep 16 '13 at 18:56
  • @LiamSorsby Hey Liam how's it going mate? What with today's high speed Internet and fast servers, I don't see the point in doing this ;-) Unless we're talking about a 50mb text file, ok, but otherwise... nah. It won't help to improve speed much unless you've got some wicked loops happening. – Funk Forty Niner Sep 16 '13 at 18:57
  • @Fred-ii- yeah i see your point really and i suppose its more to do with the functions time consumption rather then the space left between each line. – Liam Sorsby Sep 16 '13 at 19:01
  • The short ans is if you've got an opcode cache then it doesn't make any difference. If not, then the main issue is the physical I/O for file-cache misses: aggregating source files can make a material difference -- I've halved the latency on **phpBB** doing this -- see [some of my old blog articles](http://blog.ellisons.org.uk/search-phpBB) on this. – TerryE Sep 17 '13 at 18:08

1 Answers1

4

This would mostly be a waste of time and effort. The biggest reason minifying CSS/JS plays any role at all is the fact that the CSS/JS source code is transmitted across the network. Removing those extra spaces and making function names shorter saves bytes in the transmission.

Since PHP does not get transmitted across the network, there would be no benefit.

You can, however, use PHP to minify the HTML/CSS/Javascript output you send on the fly.

A caveat is something a professor once told me: "Less code tends to run faster".

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96
  • yeah as i thought, however would it have any performance increase on the server? as i maybe wrong, but minifying reduces the file size. Would this then not get interpreted quicker as i was under the impression php is interpreted line by line, so less whitespace = a quicker parsing time. or am i completely wrong with that? i know however it more then likely will be a waste of time for the performance boost you would probably get – Liam Sorsby Sep 16 '13 at 18:59
  • I'm not 100% sure about the PHP parser/interpreter, but if it is sane at all then the whitespace will only play a part when it is being parsed and tokens are being generated. Even then I doubt having 100 spaces between the current token and the next vs just 1 will make much of a difference at all. At the very least, the amount of difference it would make would not warrant the sort of crazy/outlandish methods JavaScript currently employs to be efficient as well as maintainable. – Jeff Lambert Sep 16 '13 at 19:03
  • yeah i agree, unless you have ridiculous amounts of whitespace to document, i don't think it would really make much of a difference. Thank you for your imput. And more then likely unless someone puts a riduculously good answer i believe this to be the right one – Liam Sorsby Sep 16 '13 at 19:05