How often do I need to connect to MySQL database?

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

    How often do I need to connect to MySQL database?

    Hi,
    At present at the top of each of my php pages I reconnect to my
    database

    mysql_connect(. ..);

    is that actually necessary/good practice. Isn't there something about
    persistent connections.

    --
    zzapper
    Best of VimTips


  • peter

    #2
    Re: How often do I need to connect to MySQL database?

    At present at the top of each of my php pages I reconnect to my
    database
    >
    mysql_connect(. ..);
    >
    is that actually necessary/good practice. Isn't there something about
    persistent connections.
    instead of connecting on each php page you should put your connection
    details in a seperate file and use require_once() to call it.

    This will make it easier to change and also will defend against connecting
    to the database more than once accidentally.


    Comment

    • Erwin Moller

      #3
      Re: How often do I need to connect to MySQL database?

      zzapper wrote:
      Hi,
      At present at the top of each of my php pages I reconnect to my
      database
      >
      mysql_connect(. ..);
      >
      is that actually necessary/good practice. Isn't there something about
      persistent connections.
      yes, try pconnect as in mysql_pconnect( )

      But I wouldn't expect that will seriously speed up your scripts.
      If you want to investigate: www.php.net and type mysql_pconnect into the
      searchbox.

      Regards,
      Erwin Moller
      >
      --
      zzapper
      Best of VimTips
      http://www.vim.org/tips/tip.php?tip_id=305

      Comment

      • zzapper

        #4
        Re: How often do I need to connect to MySQL database?

        On Mar 13, 8:43 pm, Erwin Moller
        <since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
        zzapperwrote:
        Hi,
        At present at the top of each of my php pages I reconnect to my
        database
        >
        mysql_connect(. ..);
        >
        is that actually necessary/good practice. Isn't there something about
        persistent connections.
        >
        yes, try pconnect as in mysql_pconnect( )
        Hi
        thnx 4 quick replies
        Yes I actually use an include for the connection.
        I assume mysql_pconnect obviates the need for require_once?

        --
        zzapper
        Best of VimTips



        Comment

        • Gordon Burditt

          #5
          Re: How often do I need to connect to MySQL database?

          >mysql_connect( ...);
          >>
          >is that actually necessary/good practice. Isn't there something about
          >persistent connections.
          >
          >yes, try pconnect as in mysql_pconnect( )
          >
          >But I wouldn't expect that will seriously speed up your scripts.
          I would expect mysql_pconnect( ) to seriously overload your MySQL
          server with idle connections unless you carefully tune it.
          >If you want to investigate: www.php.net and type mysql_pconnect into the
          >searchbox.

          Comment

          • Jerry Stuckle

            #6
            Re: How often do I need to connect to MySQL database?

            zzapper wrote:
            Hi,
            At present at the top of each of my php pages I reconnect to my
            database
            >
            mysql_connect(. ..);
            >
            is that actually necessary/good practice. Isn't there something about
            persistent connections.
            >
            --
            zzapper
            Best of VimTips

            >
            You do NOT want to use mysql_pconnect( ). This does create persistent
            connections - but now these connections will be tying up system
            resources as long as MySQL is running. And you will still have to issue
            mysql_pconnect( ) at the start of each page. And you will have to keep
            at least as many persistent connections available as your peak demand
            requires.

            mysql_pconnect( ) might be applicable if you were running 10K or more
            connections per second - but for your normal website it will hurt you
            more than it will help.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • zzapper

              #7
              Re: How often do I need to connect to MySQL database?

              On Mar 14, 3:38 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              zzapperwrote:
              Hi,
              At present at the top of each of my php pages I reconnect to my
              database
              >
              mysql_connect(. ..);
              >
              is that actually necessary/good practice. Isn't there something about
              persistent connections.
              >
              --
              zzapper
              Best of VimTips
              http://www.vim.org/tips/tip.php?tip_id=305
              >
              You do NOT want to use mysql_pconnect( ). This does create persistent
              Hi
              So is it normal to connect to the db once per page, the reason I ask
              this is that I'm getting "you gave exceeded the maximum number of
              connections per hour (400)" from my webserver, but I'm currently to
              only one accessing it!
              Does "require once" only prevent me from connecting more than once per
              page?

              --
              zzapper
              Best of VimTips



              Comment

              • Jerry Stuckle

                #8
                Re: How often do I need to connect to MySQL database?

                zzapper wrote:
                On Mar 14, 3:38 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                >zzapperwrote :
                >>Hi,
                >>At present at the top of each of my php pages I reconnect to my
                >>database
                >>mysql_connect (...);
                >>is that actually necessary/good practice. Isn't there something about
                >>persistent connections.
                >>--
                >>zzapper
                >>Best of VimTips
                >>http://www.vim.org/tips/tip.php?tip_id=305
                >You do NOT want to use mysql_pconnect( ). This does create persistent
                >
                Hi
                So is it normal to connect to the db once per page, the reason I ask
                this is that I'm getting "you gave exceeded the maximum number of
                connections per hour (400)" from my webserver, but I'm currently to
                only one accessing it!
                Does "require once" only prevent me from connecting more than once per
                page?
                >
                --
                zzapper
                Best of VimTips

                >
                >
                No, every page must make its own connection to the server. At the end
                of the page, that connection will be closed by the PHP cleanup if you
                don't do it yourself.

                What's not clear is if this is your server or a shared host. If this is
                your own server, you need to change your MySQL setup (try
                comp.databases. mysql for help). If this is a hosted server, you need to
                talk to your host.

                But if I were in this position on a hosted server, I'd find another
                host. 400 connections per hour is nothing. And if that's what they
                limit you to, chances are they're overselling their servers.


                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                Working...