Compiling PHP Code To Machine Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MBS

    Compiling PHP Code To Machine Code

    As far as I know PHP code is always a script which is interpreted by the
    PHP interpreter, compiled to machine code, then executed by the CPU. Much
    like Java, one could say. (I am not talking about the source code to PHP
    itself; rather, the code that one using the PHP language would write.)

    However, since the interpreter has to compile the PHP source prior to
    execution, it is being compiled anyway, so why not just compile it from the
    beginning and save the overhead required by the interpreter, thus allowing
    the code to run faster?

    I'm new to PHP. So I was just wondering. I'm using PHP with Apache. From
    what I understand compiled executables can be used with Apache via CGI or
    something. Not quite sure how that works.

    If anyone wishes to clue me in I'd appreciate it. Thanks.

  • ZeldorBlat

    #2
    Re: Compiling PHP Code To Machine Code

    Check out bcompiler:

    <http://www.php.net/manual/en/ref.bcompiler.p hp>

    Comment

    • NC

      #3
      Re: Compiling PHP Code To Machine Code

      MBS wrote:[color=blue]
      >
      > since the interpreter has to compile the PHP source prior to execution,
      > it is being compiled anyway, so why not just compile it from the
      > beginning and save the overhead required by the interpreter, thus
      > allowing the code to run faster?[/color]

      There is at least one PHP compiler I know of:




      The problem with compiled programs is security; it's difficult to
      ensure
      proper security on shared servers if executables are allowed. Hence,
      customer executables are not allowed on shared servers, such as those
      of Web hosting companies. Needless to say, this makes PHP compilers
      irrelevant to a very large segment of PHP users who do not expect to
      have dedicated servers at their disposal...

      Cheers,
      NC

      Comment

      • |-|erc

        #4
        Re: Compiling PHP Code To Machine Code

        "MBS" <mbs@mbs.net> wrote in ...
        : As far as I know PHP code is always a script which is interpreted by the
        : PHP interpreter, compiled to machine code, then executed by the CPU. Much
        : like Java, one could say. (I am not talking about the source code to PHP
        : itself; rather, the code that one using the PHP language would write.)
        :
        : However, since the interpreter has to compile the PHP source prior to
        : execution, it is being compiled anyway, so why not just compile it from the
        : beginning and save the overhead required by the interpreter, thus allowing
        : the code to run faster?
        :
        : I'm new to PHP. So I was just wondering. I'm using PHP with Apache. From
        : what I understand compiled executables can be used with Apache via CGI or
        : something. Not quite sure how that works.
        :
        : If anyone wishes to clue me in I'd appreciate it. Thanks.

        Interpreters don't compile! The php code is simulated by Apache, there is no associated file.exe
        that control of the CPU is passed to.

        A script will run faster with successive runs as the optimizer builds up information about the script,
        similar to compiling.

        Interpreted code has a few advantages, simpler, no hangs, dynamic content, but in future it could
        all be compiled. For 99% of sites you won't notice any difference.

        Herc



        Comment

        Working...