What is php's behavior when connect to a db?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zelzel.zsu@gmail.com

    #1

    What is php's behavior when connect to a db?

    What is php's behavior when connect to a db?

    I've been told that php was once a dominant web programing language.
    I've read a few chapters of a php book.

    I was wonder what's php's performance.

    Perl was once for a while a popular programming language for cgi.
    But start very process per one web visit cause serioius problem to
    system performance.

    And then FASTCGI born.
    I was impressed by its performance.

    But recently i learn to do some php program which connect a mysql db.
    It seems that the program run's very slow.

    So, I have 2 questions:
    1. does the os need to fork a php interpreter for every single web
    request?
    2. does the php connects to mysql all the time? that is does it need to
    connect mysql
    100 times when a user request the url 100 times?

    If the answer if yes, i think that php's performance is unacceptable.


    thanks.

  • Erwin Moller

    #2
    Re: What is php's behavior when connect to a db?

    zelzel.zsu@gmai l.com wrote:

    Hi zeszel,
    [color=blue]
    > What is php's behavior when connect to a db?[/color]

    depends on the database and the programmer.

    [color=blue]
    >
    > I've been told that php was once a dominant web programing language.[/color]

    once was?
    It still IS.
    :-)

    [color=blue]
    > I've read a few chapters of a php book.[/color]

    good.
    [color=blue]
    >
    > I was wonder what's php's performance.
    >
    > Perl was once for a while a popular programming language for cgi.[/color]

    Yes, I did a lot of Perl too, but I am really happy I can do almost anything
    in PHP nowadays.
    At least I am able to read my own code.
    ;-)

    [color=blue]
    > But start very process per one web visit cause serioius problem to
    > system performance.
    >
    > And then FASTCGI born.
    > I was impressed by its performance.[/color]

    Yes, that helped a lot.
    I made Perl resident in memory, right?
    And some precompiling-tricks too.
    [color=blue]
    >
    > But recently i learn to do some php program which connect a mysql db.
    > It seems that the program run's very slow.[/color]

    Not good.
    I expect PHP has little to do with that tough...
    [color=blue]
    >
    > So, I have 2 questions:
    > 1. does the os need to fork a php interpreter for every single web
    > request?[/color]

    How did you install PHP?
    On which OS?
    Did you install ISAPI under Windows?
    etc.

    Your question is a little hard to answer. :-)

    In general: PHP is NOT slow, and can easily handle massive requests if the
    underlying server is post-stoneage.
    (Just my personal experience, based on PHP4/5 on RH8/FreeBSD/Windows2000
    combined with IIS4/5/6 and Apache.)

    [color=blue]
    > 2. does the php connects to mysql all the time? that is does it need to
    > connect mysql
    > 100 times when a user request the url 100 times?
    >
    > If the answer if yes, i think that php's performance is unacceptable.
    >[/color]

    Well, why don't you read up bit at php.net?

    *************** ***********
    mysql_connect

    (PHP 3, PHP 4, PHP 5)
    mysql_connect -- Open a connection to a MySQL Server
    Description
    resource mysql_connect ( [string server [, string username [, string
    password [, bool new_link [, int client_flags]]]]] )

    Opens or reuses a connection to a MySQL server.

    *************** ***********

    In general: Do not worry about PHP's performance.
    Worry about the databasequeries .

    Most of the time people write bad repetive queries, and blame PHP.
    I am not saying you do that, but I just see it a lot.
    ;-)


    So if your site is very slow, try this:
    - where does the script take up its time?
    - isolate the part where the database is queried, and measure the time it
    needs to complete your query.

    You can use a crude microtime to measure roughly. It is enough to pinpoint
    to the problemerea without complex debugging/profiling tools.

    Works for me untill now in all cases.


    Good luck.

    Regrads,
    Erwin Moller
    [color=blue]
    >
    > thanks.[/color]

    Comment

    Working...