Functions "compiled" each time?

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

    Functions "compiled" each time?

    Hello all.

    I have an index.php file that has a lot of functions that I wrote.
    Let's say for the sake of argument that there are 1000 functions of
    100 lines each. The index.php file is invoked with a "state" a la
    "index.php?stat e=L1-2L3C4-47". Different functions are called
    according to what the state is, and then user actions can cause
    index.php to be invoked again with a different state. For instance,
    you can click an "erase this part" button, and the page will display
    again with that part missing.

    I don't mind if it takes even a second or two to "compile" (parse?
    condense?) the functions the first time through, but a change of state
    should take only 1/10 of a second or less. Apart from the compiling,
    that goal is achievable, the processing isn't that complicated, but if
    the php engine starts from scratch each time I pass through the file,
    I will have a problem.

    Or maybe, since it is a server-side process, rather than compiling the
    functions once for each contact with the page, the functions are
    compiled once when the first person contacts the page.

    I just have no idea how it works, and I need to know so I can plan my
    code accordingly.

    Does somebody out there have a detailed knowledge of how this is done?

    Regards,

    Rick
  • steve

    #2
    Re: Functions "compiled& quot; each time?

    "Rick70" wrote:[color=blue]
    > Hello all.
    >
    > I have an index.php file that has a lot of functions that I wrote.
    > Let’s say for the sake of argument that there are 1000 functions
    > of
    > 100 lines each. The index.php file is invoked with a "state" a[/color]
    la[color=blue]
    > "index.php?stat e=L1-2L3C4-47". Different functions are called
    > according to what the state is, and then user actions can cause
    > index.php to be invoked again with a different state. For[/color]
    instance,[color=blue]
    > you can click an "erase this part" button, and the page will[/color]
    display[color=blue]
    > again with that part missing.
    >
    > I don’t mind if it takes even a second or two to "compile"
    > (parse?
    > condense?) the functions the first time through, but a change of[/color]
    state[color=blue]
    > should take only 1/10 of a second or less. Apart from the[/color]
    compiling,[color=blue]
    > that goal is achievable, the processing isn’t that complicated,
    > but if
    > the php engine starts from scratch each time I pass through the[/color]
    file,[color=blue]
    > I will have a problem.
    >
    > Or maybe, since it is a server-side process, rather than compiling[/color]
    the[color=blue]
    > functions once for each contact with the page, the functions are
    > compiled once when the first person contacts the page.
    >
    > I just have no idea how it works, and I need to know so I can plan[/color]
    my[color=blue]
    > code accordingly.
    >
    > Does somebody out there have a detailed knowledge of how this is[/color]
    done?[color=blue]
    >
    > Regards,
    >
    > Rick[/color]

    It does start from scratch every time, and for most applications, it
    seems to be just fine. If not acceptable, then look at code caching
    s/w like mmcache and others.

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-Function...ict151290.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=506566

    Comment

    • Tim Van Wassenhove

      #3
      Re: Functions "compiled& quot; each time?

      In article <f4e56830.04091 91526.485815f1@ posting.google. com>, Rick wrote:[color=blue]
      > Hello all.
      >
      > I have an index.php file that has a lot of functions that I wrote.
      > Let's say for the sake of argument that there are 1000 functions of
      > 100 lines each. The index.php file is invoked with a "state" a la
      > "index.php?stat e=L1-2L3C4-47". Different functions are called
      > according to what the state is, and then user actions can cause
      > index.php to be invoked again with a different state. i[/color]

      I can't really see why you would like 1 big program.

      To me it seems, that writing a program for each state results in
      smaller, more maintanable programs. And if you give each program the
      name of the state, it shouldn't be that hard to convert the
      index.php?state =xxx to xxx.php either.

      --
      Tim Van Wassenhove <http://www.timvw.info>

      Comment

      • Tony Marston

        #4
        Re: Functions &quot;compiled& quot; each time?


        "Tim Van Wassenhove" <euki@pi.be> wrote in message
        news:2r73t4F16a 9cnU1@uni-berlin.de...[color=blue]
        > In article <f4e56830.04091 91526.485815f1@ posting.google. com>, Rick wrote:[color=green]
        >> Hello all.
        >>
        >> I have an index.php file that has a lot of functions that I wrote.
        >> Let's say for the sake of argument that there are 1000 functions of
        >> 100 lines each. The index.php file is invoked with a "state" a la
        >> "index.php?stat e=L1-2L3C4-47". Different functions are called
        >> according to what the state is, and then user actions can cause
        >> index.php to be invoked again with a different state. i[/color]
        >
        > I can't really see why you would like 1 big program.
        >
        > To me it seems, that writing a program for each state results in
        > smaller, more maintanable programs. And if you give each program the
        > name of the state, it shouldn't be that hard to convert the
        > index.php?state =xxx to xxx.php either.
        >
        > --
        > Tim Van Wassenhove <http://www.timvw.info>[/color]

        Agreed. One big program is BAD. Multiple smaller units are GOOD. If you look
        at my sample application at
        http://www.tonymarston.co.uk/php-mys...plication.html you will see
        that I have totally separate scripts for each of the following:
        - list multiple records
        - insert a record
        - update a record
        - view a record
        - delete a record
        - enter search criteria

        This means that each script only includes the code that IT wants, so doesn't
        bother accessing code that it is not going to use. I nay have hundreds of
        small units, but these are far easier to maintain that one huge unit.

        This idea is not new. I learnt it 30 years ago when I was a COBOL
        programmer. It is called "modular programming".

        --
        Tony Marston

        This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




        Comment

        • Rick

          #5
          Re: Functions &quot;compiled& quot; each time?

          Hello Tim.

          It would be good to break it into several web pages.

          The web page naturally breaks into sequential sections, so if there
          were some sort of "include" that would include the html output of a
          php program, I could do this:

          <include section1.php?st ate=L2-3>
          <include section2.php?st ate=L5-7>
          <include section3.php?st ate=L11-13>
          <include section4.php?st ate=L2C3-19>

          I'm not sure I would come out ahead in execution time, since these
          would have to be separate web requests in order to have separate php
          contexts (like an img=... tag).

          --

          I come from a Tcl background. In the world of Tcl, there's a tclindex
          file. Routines are searched for and loaded as they are required. Is
          there something similar in Php?

          Regards,

          Rick


          Tim Van Wassenhove <euki@pi.be> wrote in message news:<2r73t4F16 a9cnU1@uni-berlin.de>...[color=blue]
          > I can't really see why you would like 1 big program.
          >
          > To me it seems, that writing a program for each state results in
          > smaller, more maintanable programs. And if you give each program the
          > name of the state, it shouldn't be that hard to convert the
          > index.php?state =xxx to xxx.php either.[/color]

          Comment

          • Tim Van Wassenhove

            #6
            Re: Functions &quot;compiled& quot; each time?

            In article <f4e56830.04092 00502.42dc54b6@ posting.google. com>, Rick wrote:[color=blue]
            > Hello Tim.
            >
            > It would be good to break it into several web pages.
            >
            > The web page naturally breaks into sequential sections, so if there
            > were some sort of "include" that would include the html output of a
            > php program, I could do this:
            >
            ><include section1.php?st ate=L2-3>
            ><include section2.php?st ate=L5-7>
            ><include section3.php?st ate=L11-13>
            ><include section4.php?st ate=L2C3-19>[/color]

            Well for each section,

            $state = 'something';
            $_GET['state'] = $state;
            include('sectio n.php');

            Don't see your problem?




            --
            Tim Van Wassenhove <http://www.timvw.info>

            Comment

            • Rick

              #7
              Re: Functions &quot;compiled& quot; each time?

              Steve, thanks for the information. Useful and to the point.


              I ran across the answer to my problem in the writeup for the Pear
              module Cache Lite.

              <?php
              require_once("C ache/Lite.php");
              // (...)
              $cache = new Cache_Lite();
              if ($data = $Cache_Lite->get($id)) { // cache hit !
              echo($data);
              } else { // page has to be (re)constructed in $data
              require_once(". ..")
              require_once(". ..")
              // (...)
              $Cache_Lite->save($data);
              }
              ?>

              I was thinking in terms of C/C++ and a pre-processor. But in Php
              includes are dynamic. I don't have to include everything I might
              possibly need, once at the top of the file.

              Regards,

              Rick

              Comment

              Working...