How to speed up php?

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

    How to speed up php?

    I've got a problem with performance...

    I'm working on a fairly slow embedded platform (a 200 MHz ARM board).
    We run a browser and a webserver on the same platform.

    I've timed the performance, and the webserver takes between 5 and 6
    seconds to generate the page. Most of this time is spent running php.
    The webserver is buysbox's httpd daemon, which invokes php every time a
    page is served.

    I'm guessing that I could save a few seconds of this time by keeping php
    resident in memory so rather than incurring the overhead of starting it
    every time.

    So... Is this a right guess? How long does it take to load php? Is
    there some way to daemonize PHP so that it doesn't have to load up every
    time?

    I am looking for any and all suggestions to speed this beast up....

    --Yan
  • flamer die.spam@hotmail.com

    #2
    Re: How to speed up php?


    CptDondo wrote:
    I've got a problem with performance...
    >
    I'm working on a fairly slow embedded platform (a 200 MHz ARM board).
    We run a browser and a webserver on the same platform.
    >
    I've timed the performance, and the webserver takes between 5 and 6
    seconds to generate the page. Most of this time is spent running php.
    The webserver is buysbox's httpd daemon, which invokes php every time a
    page is served.
    >
    I'm guessing that I could save a few seconds of this time by keeping php
    resident in memory so rather than incurring the overhead of starting it
    every time.
    >
    So... Is this a right guess? How long does it take to load php? Is
    there some way to daemonize PHP so that it doesn't have to load up every
    time?
    >
    I am looking for any and all suggestions to speed this beast up....
    >
    --Yan
    My advice would be to stick a fresh copy of debian 3.1 stable on the
    box, no X (no gui at all), install apache and php and then save your
    php scripts onto it and load them via a network connection, if you
    havent used an OS without a gui before there will be some learning
    involved but its useful and there are lots of useful sites out there
    with step by step, and to install apache and php you just simply type
    apt-get install apache. that wil download the files and run the
    configuration.

    i have never heard of buysboxs webserver but i am sure its rubbish.

    Flamer.

    Comment

    • Adam Harvey

      #3
      Re: How to speed up php?

      On Thu, 19 Oct 2006 16:29:46 -0700, CptDondo wrote:
      So... Is this a right guess? How long does it take to load php? Is
      there some way to daemonize PHP so that it doesn't have to load up every
      time?
      >
      I am looking for any and all suggestions to speed this beast up....
      Admittedly I don't deal with embedded platforms as a rule, but you might
      like to have a look at using lighttpd <http://www.lighttpd.ne t/with PHP
      running under FastCGI, which should take out much of the process
      initialisation overhead that you're noticing now. If you have some spare
      RAM available (doubtful, I know, given the nature of the platform), you
      could also consider using an opcode cache like APC
      <http://pecl.php.net/package/APCor eAccelerator
      <http://eaccelerator.ne t/>, which would save the script(s) being parsed on
      each request.

      Having said that, it may just be that the PHP script itself is taking some
      time to execute, in which case there may not be much you can do.
      Another option available to you is to profile the PHP script using
      xdebug 2 <http://xdebug.org/>, which can generate cachegrind files you can
      then view in KCacheGrind or something similar on your development machine
      -- this might help lock down any bottlenecks within the script itself.

      Not sure how much more advice I can give you, not being an expert in the
      field, but hopefully something here can help. :)

      Adam

      --
      Adam Harvey

      To e-mail: don't make an example out of me!

      Comment

      • Chung Leong

        #4
        Re: How to speed up php?

        CptDondo wrote:
        I've got a problem with performance...
        >
        I'm working on a fairly slow embedded platform (a 200 MHz ARM board).
        We run a browser and a webserver on the same platform.
        >
        I've timed the performance, and the webserver takes between 5 and 6
        seconds to generate the page. Most of this time is spent running php.
        The webserver is buysbox's httpd daemon, which invokes php every time a
        page is served.
        >
        I'm guessing that I could save a few seconds of this time by keeping php
        resident in memory so rather than incurring the overhead of starting it
        every time.
        >
        So... Is this a right guess? How long does it take to load php? Is
        there some way to daemonize PHP so that it doesn't have to load up every
        time?
        PHP initialization is fairly expensive. A couple megs of code have to
        be loaded into ram; the ini file has to be parsed; a couple thousand
        built-in functions have to be initialized (a lot of memory allocation).
        Depending on the performance of the storage system, it could take a
        while.
        I am looking for any and all suggestions to speed this beast up....
        As suggested, use FastCGI to avoid having to start PHP every time.
        Beyond that I don't know what more could be done. Since it's an
        embedded system, there probably isn't a whole lot of memory to go
        around. The low performance could simply be the result of swapping.
        Five seconds to generate a page sounds excessive even on a slow CPU. It
        could also simply be that your PHP code is inefficient.

        Comment

        • CptDondo

          #5
          Re: How to speed up php?

          Adam Harvey wrote:
          On Thu, 19 Oct 2006 16:29:46 -0700, CptDondo wrote:
          >So... Is this a right guess? How long does it take to load php? Is
          >there some way to daemonize PHP so that it doesn't have to load up every
          >time?
          >>
          >I am looking for any and all suggestions to speed this beast up....
          >
          Admittedly I don't deal with embedded platforms as a rule, but you might
          like to have a look at using lighttpd <http://www.lighttpd.ne t/with PHP
          running under FastCGI, which should take out much of the process
          initialisation overhead that you're noticing now.
          Woo hoo! That took the generation time from about 6 seconds to just
          under a second. Some of the complicated pages still take a couple of
          seconds, but that's OK. Whee!
          If you have some spare
          RAM available (doubtful, I know, given the nature of the platform), you
          could also consider using an opcode cache like APC
          <http://pecl.php.net/package/APCor eAccelerator
          <http://eaccelerator.ne t/>, which would save the script(s) being parsed on
          each request.
          Currently I have 32 MB, but I can add more for the production if it is
          warranted.

          Thanks!

          --Yan

          Comment

          • Colin Fine

            #6
            Re: How to speed up php?

            flamer die.spam@hotmai l.com wrote:
            CptDondo wrote:
            >
            >I've got a problem with performance...
            >>
            >I'm working on a fairly slow embedded platform (a 200 MHz ARM board).
            >We run a browser and a webserver on the same platform.
            >>
            >I've timed the performance, and the webserver takes between 5 and 6
            >seconds to generate the page. Most of this time is spent running php.
            >The webserver is buysbox's httpd daemon, which invokes php every time a
            >page is served.
            >>
            >I'm guessing that I could save a few seconds of this time by keeping php
            >resident in memory so rather than incurring the overhead of starting it
            >every time.
            >>
            >So... Is this a right guess? How long does it take to load php? Is
            >there some way to daemonize PHP so that it doesn't have to load up every
            >time?
            >>
            >I am looking for any and all suggestions to speed this beast up....
            >>
            >--Yan
            >
            My advice would be to stick a fresh copy of debian 3.1 stable on the
            box, no X (no gui at all), install apache and php and then save your
            php scripts onto it and load them via a network connection, if you
            havent used an OS without a gui before there will be some learning
            involved but its useful and there are lots of useful sites out there
            with step by step, and to install apache and php you just simply type
            apt-get install apache. that wil download the files and run the
            configuration.
            >
            i have never heard of buysboxs webserver but i am sure its rubbish.
            >
            Flamer.
            >
            Your advice is worthless. If you have never heard of busybox, then you
            know nothing about embedded Linux.

            Colin

            Comment

            • CptDondo

              #7
              Re: How to speed up php?

              Colin Fine wrote:
              Your advice is worthless. If you have never heard of busybox, then you
              know nothing about embedded Linux.
              >
              Colin
              :-)

              Yup.... I wasn't going to engage, but I submitted the original patches
              to let busybox httpd run php cgi... (the developers chose not to use
              them and instead worked up their own, cleaner solution. Still, I like
              to think I prodded them into it. :-) ) I find it ironic that now I am
              not going to use busybox because of performance issues....

              --Yan

              Comment

              Working...