Compile time -vs- runtime?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thumb_42@yahoo.com

    Compile time -vs- runtime?

    Just curious and I haven't really seen anything about this anywhere.

    Is there an explanation of the stages PHP goes through in compiling -vs-
    parsing a PHP script? google resulted in lots of pages about how to
    compile PHP itself, but couldn't find anything about the stages of
    php "compilatio n"

    If I do a require_once("s omefile.php"); does somefile.php get loaded and
    parsed once for each web request? (Guess I'm wondering what PHP's
    equivelant of perl's 'use' is)

    Is there some way one could do this (psuedo code):


    // This would run ONLY once during (or just after) the file is parsed.
    // it would not run on each web request, but it's variables are usable
    // across multiple requests. perhaps things like $_SERVER and
    // $_POST/$_GET wouldn't be available (or usable)
    //
    compile_time: {
    $conf = parse_ini_file( );
    $doc = parse_xml_docum ent();
    $obj = new Expensive_Objec t();
    // Other "expensive" things.
    require_once,_n o_really_this_t ime("some_libra ry.php");
    }

    Now share $conf, $doc, $obj and other variables with each web request.

    The big question is the require_once() stuff.

    Jamie







  • Phil Roberts

    #2
    Re: Compile time -vs- runtime?

    With total disregard for any kind of safety measures thumb_42
    @yahoo.com leapt forth and uttered:
    [color=blue]
    > Is there some way one could do this (psuedo code):[/color]

    No.

    PHP re-initialises itself on every script request. Thats just the way
    it is. Although it is possible to serialise objects and store them in
    sessions which would give you some measure of persistance.

    --
    Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/

    Comment

    • thumb_42@yahoo.com

      #3
      Re: Compile time -vs- runtime?

      Phil Roberts <philrob@holyfl atnetshit.net> wrote:[color=blue]
      > With total disregard for any kind of safety measures thumb_42
      > @yahoo.com leapt forth and uttered:
      >[color=green]
      >> Is there some way one could do this (psuedo code):[/color]
      >
      > No.
      >
      > PHP re-initialises itself on every script request. Thats just the way
      > it is. Although it is possible to serialise objects and store them in
      > sessions which would give you some measure of persistance.[/color]

      Hmm.. is there an explanation some place about when a require_once()
      actually does the require? I mean, does it load and parse on each
      request too? (this is the part that I've really wondered about, I've
      heard different explanations about it, some say it compiles for speed
      but other places say it doesn't and I wonder how it manages to be
      almost as fast as a static HTML file.

      Jamie


      Comment

      • Chung Leong

        #4
        Re: Compile time -vs- runtime?


        Uzytkownik <thumb_42@yahoo .com> napisal w wiadomosci
        news:bK06c.3260 2$po.292187@att bi_s52...[color=blue]
        > Just curious and I haven't really seen anything about this anywhere.
        >
        > Is there an explanation of the stages PHP goes through in compiling -vs-
        > parsing a PHP script? google resulted in lots of pages about how to
        > compile PHP itself, but couldn't find anything about the stages of
        > php "compilatio n"
        >
        > If I do a require_once("s omefile.php"); does somefile.php get loaded and
        > parsed once for each web request? (Guess I'm wondering what PHP's
        > equivelant of perl's 'use' is)
        >
        > Is there some way one could do this (psuedo code):[/color]

        The way I understand the process is that the parser parses the PHP code into
        tokens, checking syntax along the way, the compiler turns the tokens into a
        opcode tree, then the execution unit runs the opcodes. My guess is that when
        you do a require or include, PHP parses and compile the file, then insert
        the opcodes into the main opcode tree. This happens for every request,
        unless you have the Zend Accelerator, which saves the opcode tree in share
        memory so that the initialial stages don't need to occur over and over
        again.

        Require()s used to happen during the parsing stage. This is back in the days
        of PHP3. Now it happens at run time, like include()s.


        Comment

        Working...