how does the PHP interpreter work?

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

    how does the PHP interpreter work?

    I notice that when my weblog software tries to contact
    www.weblogs.com, to use the update service, my whole site (all PHP)
    slows down. Contacting www.weblogs.com can take a long time. I can't
    figure out what is going on, unless the PHP interpreter gets bogged
    down trying to contact www.weblogs.com, and so is less able to serve
    up PHP pages to other website visitors. But if the PHP interpreter was
    that vulnerable to slow-downs, it doesn't seem like PHP could scale to
    handle large sites, and I know that it runs some very large sites.

    What sort of situations can slow down the PHP interpreter?
  • Phil Roberts

    #2
    Re: how does the PHP interpreter work?

    lkrubner@geocit ies.com (lawrence) emerged reluctantly from the
    curtain and staggered drunkenly up to the mic. In a cracked and
    slurred voice he muttered:
    [color=blue]
    > What sort of situations can slow down the PHP interpreter?
    >[/color]

    Most of the time the bottleneck is the database server, not the
    language interpreter.

    --
    Phil Roberts | Without me its just aweso. | http://www.flatnet.net/

    "Mankind differs from the animals only by a little,
    and most people throw that away."
    - Confucious

    Comment

    • steve

      #3
      Re: Re: how does the PHP interpreter work?

      > lkrubner@geocit ies.com (lawrence) emerged reluctantly from the[color=blue]
      > curtain and staggered drunkenly up to the mic. In a cracked and
      > slurred voice he muttered:
      >[color=green]
      > > What sort of situations can slow down the PHP interpreter?
      > >[/color]
      >
      > Most of the time the bottleneck is the database server, not the
      > language interpreter.
      >[/color]
      Agree with Phil. Your log files are probably big, and you run into
      problems accessing them. Try to reduce the size.

      DB is the culprit 90% (or 95%) of the times. Simply adding more
      memory, caching keys, doing a better structure (including
      denormalization of schema), optimizing tables usually does the trick.

      --
      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-interpre...ict125397.html
      Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=418231

      Comment

      • CJ Llewellyn

        #4
        Re: how does the PHP interpreter work?

        "lawrence" <lkrubner@geoci ties.com> wrote in message
        news:da7e68e8.0 407010845.48283 05a@posting.goo gle.com...[color=blue]
        > I notice that when my weblog software tries to contact
        > www.weblogs.com, to use the update service, my whole site (all PHP)
        > slows down. Contacting www.weblogs.com can take a long time. I can't
        > figure out what is going on, unless the PHP interpreter gets bogged
        > down trying to contact www.weblogs.com, and so is less able to serve
        > up PHP pages to other website visitors. But if the PHP interpreter was
        > that vulnerable to slow-downs, it doesn't seem like PHP could scale to
        > handle large sites, and I know that it runs some very large sites.
        >
        > What sort of situations can slow down the PHP interpreter?[/color]

        Trying to read a stream of data over the Internet.



        Comment

        • lawrence

          #5
          Re: how does the PHP interpreter work?

          "CJ Llewellyn" <satest@tmslife line.com> wrote in message news:<cc3836$uc 4$1@slavica.ukp ost.com>...[color=blue]
          > "lawrence" <lkrubner@geoci ties.com> wrote in message
          > news:da7e68e8.0 407010845.48283 05a@posting.goo gle.com...[color=green]
          > > I notice that when my weblog software tries to contact
          > > www.weblogs.com, to use the update service, my whole site (all PHP)
          > > slows down. Contacting www.weblogs.com can take a long time. I can't
          > > figure out what is going on, unless the PHP interpreter gets bogged
          > > down trying to contact www.weblogs.com, and so is less able to serve
          > > up PHP pages to other website visitors. But if the PHP interpreter was
          > > that vulnerable to slow-downs, it doesn't seem like PHP could scale to
          > > handle large sites, and I know that it runs some very large sites.
          > >
          > > What sort of situations can slow down the PHP interpreter?[/color]
          >
          > Trying to read a stream of data over the Internet.[/color]

          I'm not sure my question was understood. Let me clarify this, please,
          with another question. Let's pose this as a hypothetical. Suppose I
          have a website at www.myDomain.com. It is all PHP. Someone comes to
          visit the site. The PHP script that renders the page needs to open an
          RSS feed on another website, and then it renders that RSS with a style
          sheet. It takes the PHP 10 seconds to get the RSS and render the page.
          However, 2 seconds after the first visitor arrived, a second visitor
          comes to the site. Are you saying that PHP can not begin to render any
          pages for the second visitor until it is done reading the stream of
          data over the Internet for the first visitor? That is, the second
          visitor must wait 8 seconds before the PHP interpreter even begins to
          work on rendering a page for them?

          If this is the way PHP works, then how does PHP scale up to sites that
          serve millions of hits a week? If the average PHP script took 1 second
          to run, then a PHP site would be unable to serve more than 86400 pages
          a day.

          Comment

          • Chris Hope

            #6
            Re: Re: how does the PHP interpreter work?

            steve wrote:
            [color=blue]
            > DB is the culprit 90% (or 95%) of the times.  Simply adding more
            > memory, caching keys, doing a better structure (including
            > denormalization of schema), optimizing tables usually does the trick.[/color]

            And don't forget to index tables as well. I've often seen tables with no
            indexes that struggle because there's so much data in them. As soon as
            indexes are added on the appropriate columns they're nice and fast.

            --
            Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

            Comment

            • R. Rajesh Jeba Anbiah

              #7
              Re: how does the PHP interpreter work?

              lkrubner@geocit ies.com (lawrence) wrote in message news:<da7e68e8. 0407010845.4828 305a@posting.go ogle.com>...[color=blue]
              > I notice that when my weblog software tries to contact
              > www.weblogs.com, to use the update service, my whole site (all PHP)
              > slows down. Contacting www.weblogs.com can take a long time. I can't
              > figure out what is going on, unless the PHP interpreter gets bogged
              > down trying to contact www.weblogs.com, and so is less able to serve
              > up PHP pages to other website visitors. But if the PHP interpreter was
              > that vulnerable to slow-downs, it doesn't seem like PHP could scale to
              > handle large sites, and I know that it runs some very large sites.[/color]

              Perhaps session locking? <http://in2.php.net/session_write_c lose>

              --
              | Just another PHP saint |
              Email: rrjanbiah-at-Y!com

              Comment

              • Phil Roberts

                #8
                Re: how does the PHP interpreter work?

                lkrubner@geocit ies.com (lawrence) emerged reluctantly from the
                curtain and staggered drunkenly up to the mic. In a cracked and
                slurred voice he muttered:
                [color=blue]
                > Are you saying that PHP can not begin to render any
                > pages for the second visitor until it is done reading the stream
                > of data over the Internet for the first visitor? That is, the
                > second visitor must wait 8 seconds before the PHP interpreter
                > even begins to work on rendering a page for them?[/color]

                Yes.
                [color=blue]
                >
                > If this is the way PHP works, then how does PHP scale up to
                > sites that serve millions of hits a week? If the average PHP
                > script took 1 second to run, then a PHP site would be unable to
                > serve more than 86400 pages a day.
                >[/color]

                Most such sites do not rely on external data. That or they use
                cacheing to reduce the number of remote data transfers. The Magpie
                RSS library enables the RSS data to be cached in order to speed up
                rendering.

                --
                Phil Roberts | Without me its just aweso. | http://www.flatnet.net/

                "Mankind differs from the animals only by a little,
                and most people throw that away."
                - Confucious

                Comment

                • lawrence

                  #9
                  Re: how does the PHP interpreter work?

                  Phil Roberts <phil.roberts@g ooglemail.com> wrote in message news:<Xns9524A0 62BB55Ephilrobe rts@216.196.97. 132>...[color=blue]
                  > lkrubner@geocit ies.com (lawrence) emerged reluctantly from the
                  > curtain and staggered drunkenly up to the mic. In a cracked and
                  > slurred voice he muttered:
                  >[color=green]
                  > > Are you saying that PHP can not begin to render any
                  > > pages for the second visitor until it is done reading the stream
                  > > of data over the Internet for the first visitor? That is, the
                  > > second visitor must wait 8 seconds before the PHP interpreter
                  > > even begins to work on rendering a page for them?[/color]
                  >
                  > Yes.
                  >[color=green]
                  > >
                  > > If this is the way PHP works, then how does PHP scale up to
                  > > sites that serve millions of hits a week? If the average PHP
                  > > script took 1 second to run, then a PHP site would be unable to
                  > > serve more than 86400 pages a day.
                  > >[/color]
                  >
                  > Most such sites do not rely on external data. That or they use
                  > cacheing to reduce the number of remote data transfers. The Magpie
                  > RSS library enables the RSS data to be cached in order to speed up
                  > rendering.[/color]

                  You are insisting that most PHP scripts run in much less than a
                  second. Is this true? It is the clear implication of what you've
                  written. There are only 86400 seconds in a day, so no PHP site would
                  be able to scale beyond that point, unless it could run in less than a
                  second. You could not do a site like Slashdot using PHP, unless the
                  code ran in less than a second, on average. Is this what you are
                  saying? You are saying that PHP is unable to handle 2 (or 100)
                  visitors concurrently. I find that hard to believe.

                  Suppose you want to run a site like Slashdot using PHP. Suppose the
                  database connection is occassionally hard to get. The average time for
                  a script might run up to 1 second, and then you can no longer support
                  your site. What would the solution be then? Switch to Perl?

                  Can I ask where you got your information? I'd like to do more research
                  on this subject. Your argument surprises me. If you are right, then
                  PHP seems much more limited than I thought.

                  Comment

                  • Tony Marston

                    #10
                    Re: how does the PHP interpreter work?


                    "lawrence" <lkrubner@geoci ties.com> wrote in message
                    news:da7e68e8.0 407142158.50cc3 2d8@posting.goo gle.com...[color=blue]
                    > Phil Roberts <phil.roberts@g ooglemail.com> wrote in message[/color]
                    news:<Xns9524A0 62BB55Ephilrobe rts@216.196.97. 132>...[color=blue][color=green]
                    > > lkrubner@geocit ies.com (lawrence) emerged reluctantly from the
                    > > curtain and staggered drunkenly up to the mic. In a cracked and
                    > > slurred voice he muttered:
                    > >[color=darkred]
                    > > > Are you saying that PHP can not begin to render any
                    > > > pages for the second visitor until it is done reading the stream
                    > > > of data over the Internet for the first visitor? That is, the
                    > > > second visitor must wait 8 seconds before the PHP interpreter
                    > > > even begins to work on rendering a page for them?[/color]
                    > >
                    > > Yes.[/color][/color]

                    This is crap. A web server like Apache can run multiple threads at the same
                    time, and as each HTTP request comes in it is handed over to the first
                    available thread. It is therefore possible to have multiple instances of PHP
                    being executed at the same time as each instance is within its own thread.
                    having the ability to allow multiple concurrent threads is a function of the
                    web server, not PHP.

                    --
                    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

                    • Gordon Burditt

                      #11
                      Re: how does the PHP interpreter work?

                      >> > Are you saying that PHP can not begin to render any[color=blue][color=green][color=darkred]
                      >> > pages for the second visitor until it is done reading the stream
                      >> > of data over the Internet for the first visitor? That is, the
                      >> > second visitor must wait 8 seconds before the PHP interpreter
                      >> > even begins to work on rendering a page for them?[/color]
                      >>
                      >> Yes.[/color][/color]

                      I don't agree, when PHP is used as an Apache module for even an
                      ancient version of Apache (e.g. 1.3.1, and I suspect 1.1 as well),
                      or as a CGI. Apache runs several concurrent processes (or threads).
                      I have one page that can take considerable time to generate (e.g.
                      20 minutes to overnight), due to heavy database activity, and I
                      have no trouble getting OTHER PHP pages from the same server in a
                      different browser window during that time. This page really ought
                      to cache its output, but not while I'm still debugging the output.

                      Database locking is a separate issue.
                      [color=blue][color=green][color=darkred]
                      >> > If this is the way PHP works, then how does PHP scale up to
                      >> > sites that serve millions of hits a week? If the average PHP
                      >> > script took 1 second to run, then a PHP site would be unable to
                      >> > serve more than 86400 pages a day.[/color][/color][/color]

                      If a script averages more than one *CPU* second a day, then you run
                      out of CPU horsepower with 86400 hits a day. Solution: get a
                      faster CPU, use multiple processors, add more memory, or round-robin
                      multiple servers. Or make the code run faster.

                      If a script averages more than one second *clock execution time*,
                      say, due to a few people who insist on doing PPP over 300 bps links,
                      or your database uses stone carvings as a storage medium, no problem,
                      except for the impatient users. Multiple PHP threads (for different
                      requests) can run at once (except in the presence of locking, where
                      the code deliberately avoids multiple threads doing certain things).
                      [color=blue][color=green]
                      >> Most such sites do not rely on external data. That or they use
                      >> cacheing to reduce the number of remote data transfers. The Magpie
                      >> RSS library enables the RSS data to be cached in order to speed up
                      >> rendering.[/color]
                      >
                      >You are insisting that most PHP scripts run in much less than a
                      >second. Is this true?[/color]

                      CPU second, probably. Real-time-clock second, I doubt it and I
                      really don't care - it won't limit the number of visitors.
                      [color=blue]
                      >It is the clear implication of what you've
                      >written. There are only 86400 seconds in a day, so no PHP site would
                      >be able to scale beyond that point, unless it could run in less than a
                      >second. You could not do a site like Slashdot using PHP, unless the
                      >code ran in less than a second, on average. Is this what you are
                      >saying? You are saying that PHP is unable to handle 2 (or 100)
                      >visitors concurrently. I find that hard to believe.[/color]

                      As do I, and I have demonstrated this to my own satisfaction. Try,
                      for example, putting up a PHP page that goes into an infinite loop
                      (the run time limit will get it eventually - try setting it for 24
                      hours). With Apache you can still view other pages - at least on
                      an OS with a decent scheduler (and I believe all forms of UNIX
                      qualify, and I thought even various versions of Windows NT and
                      successors did also).
                      [color=blue]
                      >Suppose you want to run a site like Slashdot using PHP. Suppose the
                      >database connection is occassionally hard to get. The average time for
                      >a script might run up to 1 second, and then you can no longer support
                      >your site. What would the solution be then? Switch to Perl?[/color]

                      If there really were a single-thread limit like this, it would
                      probably be an Apache (or whatever web server) problem, and it would
                      apply equally to PHP, Perl, CGI written in C, or whatever. I think
                      you can create this problem in Apache by setting "MaxClients 1".
                      This is NOT a setting you want for a production web server, or even
                      a toy web server with only one user ever (browsers often request
                      images in parallel, so one user can easily be responsible for 4
                      simultaneous requests even if he has only one browser window open.
                      And yes, images can be generated by PHP - sometimes this is used
                      by pay sites to protect against deep linking). The distributed
                      default for this seems to be "MaxClients 150", and for a major site
                      like slashdot, you'd want to raise it a lot.
                      [color=blue]
                      >Can I ask where you got your information? I'd like to do more research
                      >on this subject. Your argument surprises me. If you are right, then
                      >PHP seems much more limited than I thought.[/color]

                      Gordon L. Burditt

                      Comment

                      • Phil Roberts

                        #12
                        Re: how does the PHP interpreter work?

                        "Tony Marston" <tony@NOSPAM.de mon.co.uk> emerged reluctantly from
                        the curtain and staggered drunkenly up to the mic. In a cracked
                        and slurred voice he muttered:
                        [color=blue]
                        > This is crap. A web server like Apache can run multiple threads
                        > at the same time, and as each HTTP request comes in it is handed
                        > over to the first available thread. It is therefore possible to
                        > have multiple instances of PHP being executed at the same time
                        > as each instance is within its own thread. having the ability to
                        > allow multiple concurrent threads is a function of the web
                        > server, not PHP.
                        >[/color]

                        The question was in relation to the fetching of remote XML data
                        feeds though. In which case PHP will not render the data until it
                        has been fetched. Network lag, not interpreter lag. Sorry for any
                        confusion.

                        --
                        Phil Roberts | Without me its just aweso. | http://www.flatnet.net/

                        "Mankind differs from the animals only by a little,
                        and most people throw that away."
                        - Confucious

                        Comment

                        • Gordon Burditt

                          #13
                          Re: how does the PHP interpreter work?

                          >> This is crap. A web server like Apache can run multiple threads[color=blue][color=green]
                          >> at the same time, and as each HTTP request comes in it is handed
                          >> over to the first available thread. It is therefore possible to
                          >> have multiple instances of PHP being executed at the same time
                          >> as each instance is within its own thread. having the ability to
                          >> allow multiple concurrent threads is a function of the web
                          >> server, not PHP.
                          >>[/color]
                          >
                          >The question was in relation to the fetching of remote XML data
                          >feeds though. In which case PHP will not render the data until it
                          >has been fetched. Network lag, not interpreter lag. Sorry for any
                          >confusion.[/color]

                          Network lag on one page should not affect other pages much unless
                          the network (or the other end of the connection) is really being
                          saturated, or there's some locking going on (like it's enforced
                          that only one PHP process will go get fresh data from the feed when
                          the cached data is older than X minutes, and if another process
                          wants it, it will wait for the first process to get it, then use
                          it).

                          Gordon L. Burditt

                          Comment

                          Working...