Skip to main content

Why compile a PHP File?


a friend of mine told me recently "to optimize your site you may want compile your php files" and i was like "what?"



i honestly i never heard of that, i'm a "advanced-naive" prgrammer, that means i'm self taught, i built complex sites but i'm still missing something...



bottom line: what does it mean compile php? convert them in exe files? why? is faster?


Source: Tips4allCCNA FINAL EXAM

Comments

  1. While PHP code needs to be interpreted on every call, bytecode is precompiled code that runs almost instantly.
    Mostly you will only really need it, if you are running a larger website.

    The following tools can be used to compile scripts or run compiled scripts:


    eAccelerator
    Zend Optimizer
    PHC (http://www.phpcompiler.org/)
    Alternative PHP Cache (APC)

    ReplyDelete
  2. Unless you're after serious performance then compiling PHP using something like Facebook's HipHop is probably a bit excessive.

    I'd just install/configure APC on your machine which will cache the compiled bytecode and should give you an instant performance boost.

    ReplyDelete
  3. Facebook use such things. Their product is hiphop, and it's free.

    ReplyDelete
  4. The idea of a compiler, is to convert human readble code (C, PHP, Java etc), into machine readable code. When you execute your PHP scripts, they are interpreted (almost inline compilation), which means they are read a line by line, and the code is executed accordingly.

    Compiled code, means that it is compiled at source, therefore is already in machine language (or byte code for VM languages like Java), and therefore, the server does not have to interpret the code each time. This makes it quicker.

    Facebook created a PHP compiler to speed up their site. The idea of compiled code is that usually, once it is written, it doesn't change for a while, so there is an overhead in having to interpret it into machine language each time the code is executed. That is why your friend means by optimize.

    It will therefore be converted into machine language or bytecode (not exe, but effecively the same concept).

    ReplyDelete
  5. The bigger your application the more sense this makes. PHP loads your whole program into memory and then compiles it on the fly: meaning as it needs to be used. So if you pre-compile it should skip that step. Facebook does something like this. The translate their php into C++ via something called hip hop. Not exactly the same thing but you get the idea.

    I doubt this will show you much difference on smaller applications.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex