Closing MySQL Connections

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

    Closing MySQL Connections

    Hey all,

    Here's a question for you, my hosts have told me that that one my pages,
    php, was causing their server to reboot because there were too many open
    connections and that they should be closed.

    Now, correct me if I am wrong but I thought that the connections were closed
    after a minute of inactivity.

    Does this sound right? Could open connections cause their server to reboot a
    lot, say 3 times in 15 minutes? If so, what can I do about it?

    Any insight is welcome,

    Anthony


  • andreas.maurer1971@web.de

    #2
    Re: Closing MySQL Connections



    Anthony schrieb:[color=blue]
    > Hey all,
    >
    > Here's a question for you, my hosts have told me that that one my pages,
    > php, was causing their server to reboot because there were too many open
    > connections and that they should be closed.
    >
    > Now, correct me if I am wrong but I thought that the connections were closed
    > after a minute of inactivity.
    >
    > Does this sound right? Could open connections cause their server to reboot a
    > lot, say 3 times in 15 minutes? If so, what can I do about it?
    >
    > Any insight is welcome,
    >
    > Anthony[/color]

    Hi Anthony,

    usually you always should issue the statement mysql_close() at the end
    of each php- page. This closes the mysql connection that got opened
    during the script.

    In case you use the command mysql_pconnect( ) to connect to MySQL you
    must(!!) use mysql_close() at the end as otherwise your connections
    will be left open for x amount of time. How long should be defined
    somewhere in the ini-files of MySQL but I'm not sure where.

    Otherwise and recommended practice is the command mysql_connect() as a
    means to connect to MySQL as at the end of the script the recently
    opened connection gets closed automatically and no mysql_close() is
    needed but, of course, still should be issued.

    To answer your question whether it is possible that too many open
    connections can cause a server to reboot I can't give you any input but
    to me this sounds logical. Of course the definition of "how many is too
    many" depends on many different things and the question how often a
    reboot might be required depends on the amount of traffic you have on
    your website. A lot of traffic = a lot of open connections => server
    reboots sooner ;-)

    HTH,

    Andy

    Comment

    • Wim Roffil

      #3
      Re: Closing MySQL Connections

      Since updating to Mysql 4.1 I see the same problem: my connections are not
      anymore automaticaly closed when the PHP program ends. Every time when I
      restart my computer and run a MYISAMCHK I get warnings of open connections.

      I am afraid that I will have to become religious in closing all connections
      before the PHP script ends (and pray that after that it will work).

      MySql 4.1: New: yes Improved: ????

      Wim



      "Anthony" <news@startrekf reedom.com> schreef in bericht
      news:42a40c7d$0 $10304$afc38c87 @news.optusnet. com.au...[color=blue]
      > Hey all,
      >
      > Here's a question for you, my hosts have told me that that one my pages,
      > php, was causing their server to reboot because there were too many open
      > connections and that they should be closed.
      >
      > Now, correct me if I am wrong but I thought that the connections were[/color]
      closed[color=blue]
      > after a minute of inactivity.
      >
      > Does this sound right? Could open connections cause their server to reboot[/color]
      a[color=blue]
      > lot, say 3 times in 15 minutes? If so, what can I do about it?
      >
      > Any insight is welcome,
      >
      > Anthony
      >
      >[/color]


      Comment

      • Anthony

        #4
        Re: Closing MySQL Connections

        Okay, thanks Wim, looks like I have a few mysql_close($co nnection) commands
        to add to my code.

        Cheers,

        Anthony

        "Wim Roffil" <wimroffel@plea se_no_spam-planet.nl> wrote in message
        news:d81s72$ive $1@reader11.wxs .nl...[color=blue]
        > Since updating to Mysql 4.1 I see the same problem: my connections are not
        > anymore automaticaly closed when the PHP program ends. Every time when I
        > restart my computer and run a MYISAMCHK I get warnings of open
        > connections.
        >
        > I am afraid that I will have to become religious in closing all
        > connections
        > before the PHP script ends (and pray that after that it will work).
        >
        > MySql 4.1: New: yes Improved: ????
        >
        > Wim[/color]
        [color=blue]
        >[/color]


        Comment

        Working...