What is that function called again? Time taken to do script.

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

    What is that function called again? Time taken to do script.

    Hi,

    I recall a function that would tell me how long it took to generate an
    output.
    But for the life of me I cannot remember it.

    Dow anybody know it? Or do I have to write something myself, (using time?).

    Sims


  • Brendan Donahue

    #2
    Re: What is that function called again? Time taken to do script.

    Sims wrote:
    [color=blue]
    > Hi,
    >
    > I recall a function that would tell me how long it took to generate an
    > output.
    > But for the life of me I cannot remember it.
    >
    > Dow anybody know it? Or do I have to write something myself, (using
    > time?).
    >
    > Sims[/color]
    Maybe there is a function I don't know about, but I have seen most people do
    this by running microtime() at the beginning and end of the script, and
    subtracting. I think its useless for your average script which takes less
    than 2 seconds, because microtime is in no way precise.

    Comment

    • Jon Kraft

      #3
      Re: What is that function called again? Time taken to do script.

      "Sims" <siminfrance@ho tmail.com> wrote:
      [color=blue]
      > I recall a function that would tell me how long it took to generate an
      > output.
      > But for the life of me I cannot remember it.
      >
      > Dow anybody know it? Or do I have to write something myself, (using
      > time?).[/color]

      You can use microtime(). Example of what you're after in the manual:
      PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


      HTH;
      JOn

      Comment

      • Sims

        #4
        Re: What is that function called again? Time taken to do script.


        "Jon Kraft" <jon@jonux.co.u k> wrote in message
        news:Xns94D0790 13C6C9jonjonuxc ouk@130.133.1.4 ...[color=blue]
        > "Sims" <siminfrance@ho tmail.com> wrote:
        >[color=green]
        > > I recall a function that would tell me how long it took to generate an
        > > output.
        > > But for the life of me I cannot remember it.
        > >
        > > Dow anybody know it? Or do I have to write something myself, (using
        > > time?).[/color]
        >
        > You can use microtime(). Example of what you're after in the manual:
        > http://uk.php.net/manual/en/function.microtime.php
        >[/color]

        Thanks all, I will use microtime, I just want to make sure that the scrip
        does not take too long.

        But on the same subject, what is "too long" how small should I keep my
        script in KB for it to be 'acceptable?
        I saw an article that a page should not take 'more than 30 seconds', surely
        30 seconds is far too long for one page.

        Regards.

        Sims.


        Comment

        • David Mackenzie

          #5
          Re: What is that function called again? Time taken to do script.

          On Mon, 19 Apr 2004 12:56:00 +0100, "Sims" <siminfrance@ho tmail.com>
          wrote:
          [color=blue]
          >
          >"Jon Kraft" <jon@jonux.co.u k> wrote in message
          >news:Xns94D079 013C6C9jonjonux couk@130.133.1. 4...[color=green]
          >> "Sims" <siminfrance@ho tmail.com> wrote:
          >>[color=darkred]
          >> > I recall a function that would tell me how long it took to generate an
          >> > output.
          >> > But for the life of me I cannot remember it.
          >> >
          >> > Dow anybody know it? Or do I have to write something myself, (using
          >> > time?).[/color]
          >>
          >> You can use microtime(). Example of what you're after in the manual:
          >> http://uk.php.net/manual/en/function.microtime.php
          >>[/color]
          >
          >Thanks all, I will use microtime, I just want to make sure that the scrip
          >does not take too long.
          >
          >But on the same subject, what is "too long" how small should I keep my
          >script in KB for it to be 'acceptable?[/color]

          You can't really infer a correlation between the filesize of the
          script and its execution time. A script that performs a lot of
          database queries or fetches data from some other server will/may take
          longer than one that does not.
          [color=blue]
          >I saw an article that a page should not take 'more than 30 seconds', surely
          >30 seconds is far too long for one page.[/color]

          If you are developing an intranet page that generates a complex report
          and the users know that it will take that long, you can probably get
          away with it. On a shared server, the server owners may not like your
          script taking up that much CPU time, and users may not wait 30
          seconds.

          It really depends on the situation.

          --
          David ( @priz.co.uk )

          Comment

          • Sims

            #6
            Re: What is that function called again? Time taken to do script.

            [color=blue][color=green]
            > >But on the same subject, what is "too long" how small should I keep my
            > >script in KB for it to be 'acceptable?[/color]
            >
            > You can't really infer a correlation between the filesize of the
            > script and its execution time. A script that performs a lot of
            > database queries or fetches data from some other server will/may take
            > longer than one that does not.[/color]

            Sorry by file size I wanted to say the packet been sent to the browser/user,
            not the size of the script.
            Because yes, sending a file bigger than 100/200k would not be practical,
            (and more importantly if it can be monitored then it useful to know).

            How would I calculate/estimate the size of the packet sent?
            [color=blue]
            >[color=green]
            > >I saw an article that a page should not take 'more than 30 seconds',[/color][/color]
            surely[color=blue][color=green]
            > >30 seconds is far too long for one page.[/color]
            >
            > If you are developing an intranet page that generates a complex report
            > and the users know that it will take that long, you can probably get
            > away with it. On a shared server, the server owners may not like your
            > script taking up that much CPU time, and users may not wait 30
            > seconds.
            >
            > It really depends on the situation.
            >[/color]

            Of course, but knowing how long it takes might also be useful.
            If I do not want *any* page to be more than x seconds then I could, (try
            and), monitor those pages.

            Sims


            Comment

            • DB McGee

              #7
              Re: What is that function called again? Time taken to do script.

              Sims wrote:[color=blue]
              > Sorry by file size I wanted to say the packet been sent to the browser/user,
              > not the size of the script.
              > Because yes, sending a file bigger than 100/200k would not be practical,
              > (and more importantly if it can be monitored then it useful to know).
              >
              > How would I calculate/estimate the size of the packet sent?[/color]

              PHP is server-side - the file size of the PHP script has absolutely no
              correlation to the amount of data sent to the user's browser. You could
              easily write a tiny PHP script that could send megabytes of data to a
              user's browser.

              eg.
              <?php
              for( $i=0; $i<1000000000; $i++ ) {
              echo "Here's some data<br>";
              }
              ?>

              Ultimately, the size of what the user will receive in their browser
              depends on the

              1) The size of the generated HTML
              2) embedded/linked content within that HTML file - images, flash, movies
              etc.

              So are asking how using PHP you can calculate the total of #1 & #2 for a
              given script output?

              Comment

              • Sims

                #8
                Re: What is that function called again? Time taken to do script.

                >[color=blue]
                > PHP is server-side - the file size of the PHP script has absolutely no
                > correlation to the amount of data sent to the user's browser. You could
                > easily write a tiny PHP script that could send megabytes of data to a
                > user's browser.
                >
                > eg.
                > <?php
                > for( $i=0; $i<1000000000; $i++ ) {
                > echo "Here's some data<br>";
                > }
                > ?>
                >
                > Ultimately, the size of what the user will receive in their browser
                > depends on the
                >
                > 1) The size of the generated HTML
                > 2) embedded/linked content within that HTML file - images, flash, movies
                > etc.
                >
                > So are asking how using PHP you can calculate the total of #1 & #2 for a
                > given script output?[/color]

                But as a server side operation php create something that will be sent to the
                browser, (HTML page, links etc).
                So yes I would be curious to see the size of what is sent, (including
                images).

                But I realise that it is not an easy task but using

                <?php
                for( $I=0; $i<1000000000; $i++ ) {
                echo "Here's some data<br>";
                }
                ?>

                I can guess how big the final output will be, (and add the size of images).

                With the size I could then make an educated guess if the pages is too big
                and needs to be trimmed.

                Sims


                Comment

                • Virgil Green

                  #9
                  Re: What is that function called again? Time taken to do script.

                  "Sims" <siminfrance@ho tmail.com> wrote in message
                  news:c6174b$6eq 6p$1@ID-162430.news.uni-berlin.de...[color=blue][color=green]
                  > >
                  > > PHP is server-side - the file size of the PHP script has absolutely no
                  > > correlation to the amount of data sent to the user's browser. You could
                  > > easily write a tiny PHP script that could send megabytes of data to a
                  > > user's browser.
                  > >
                  > > eg.
                  > > <?php
                  > > for( $i=0; $i<1000000000; $i++ ) {
                  > > echo "Here's some data<br>";
                  > > }
                  > > ?>
                  > >
                  > > Ultimately, the size of what the user will receive in their browser
                  > > depends on the
                  > >
                  > > 1) The size of the generated HTML
                  > > 2) embedded/linked content within that HTML file - images, flash, movies
                  > > etc.
                  > >
                  > > So are asking how using PHP you can calculate the total of #1 & #2 for a
                  > > given script output?[/color]
                  >
                  > But as a server side operation php create something that will be sent to[/color]
                  the[color=blue]
                  > browser, (HTML page, links etc).
                  > So yes I would be curious to see the size of what is sent, (including
                  > images).
                  >
                  > But I realise that it is not an easy task but using
                  >
                  > <?php
                  > for( $I=0; $i<1000000000; $i++ ) {
                  > echo "Here's some data<br>";
                  > }
                  > ?>
                  >
                  > I can guess how big the final output will be, (and add the size of[/color]
                  images).[color=blue]
                  >
                  > With the size I could then make an educated guess if the pages is too big
                  > and needs to be trimmed.
                  >
                  > Sims[/color]

                  Use output buffering and use ob_get_length to get the size of the data being
                  streamed. Note that your images are actually separate retrieves. Most like
                  you are including <img> tags. Right? As such, you will output a stream of
                  html and the browser will then make an additional request to get the actual
                  image. You could determine what images will be requested as you build the
                  html and then get their sizes and add them to the size of the html you find
                  in the output buffer.

                  See http://us2.php.net/manual/en/ref.outcontrol.php for more info on output
                  buffering/control.

                  - Virgil


                  Comment

                  • David Mackenzie

                    #10
                    Re: What is that function called again? Time taken to do script.

                    On Mon, 19 Apr 2004 15:33:20 +0100, "Sims" <siminfrance@ho tmail.com>
                    wrote:
                    [color=blue]
                    >How would I calculate/estimate the size of the packet sent?[/color]

                    Opera has an "Info" panel that displays the size of the requested
                    resource and also the total size of all the inline elements (images,
                    stylesheets, etc).
                    [color=blue][color=green]
                    >> If you are developing an intranet page that generates a complex report
                    >> and the users know that it will take that long, you can probably get
                    >> away with it. On a shared server, the server owners may not like your
                    >> script taking up that much CPU time, and users may not wait 30
                    >> seconds.[/color]
                    >
                    >Of course, but knowing how long it takes might also be useful.
                    >If I do not want *any* page to be more than x seconds then I could, (try
                    >and), monitor those pages.[/color]

                    If your page does a lot of queries or other processing then it's
                    probably useful to check how long it takes.

                    --
                    David ( @priz.co.uk )

                    Comment

                    Working...