Dear all,

What is the difference between mysql_connect() and mysql_pconnect()? From my only knowledge, mysql_pconnect is a "persistent link" command, which cannot close the mysql process by mysql_close(). If the mysql process cannot be closed, I think it may waste a lot of resource of the server. I would like to ask what's the function of mysql_pconnect()?

Thanks
Simon

    if database server is busy enought, (hundreds connection at the moment) using pconnect is good.

    in pconnect command server uses the same connection for many clients. because in pconnect connection dont disconneting. server uses same link to execute other clients query. it makes servers fast.

    in servers whch are not so busy, it isnt important to use pconnect or connect. you can use both..

      I do not agree with you, last week I had problems with some mysql_pconnect() scripts I had in my code, my server had problems with it. DO NOT USE mysql_pconnect, you will have future problems if you do so.

      Pepe Peinado

        what kind of problem ?

        Too many connections? or something else ? are you using local database or free hosting?

          This is what my host adminitrator said to me:

          "Mostly you are noticing the problems now
          because another of our clients (who regularly gets a lot of hits) decided
          to try mysql_pconnect too. Basically for each client who uses pconnect
          you get numclientsnumsustainedhits connections to the database. So if 1
          person is using pconnect, that equals roughly 150 connections to the
          database. If 4 people (lets say
          *, *, the client I
          mentioned above, and one other), then that means 600 connections to the
          database (plus the regular 50 or so that the connect version could be
          using at any given time). Now lets say that our new high performance
          servers spike up usage to 300 http connections every so often. (150 is
          about average normal simultaneous connections to our servers) At 300
          apache processes, and connections to 4 databases, that totals 1200 (for
          the pconnects, +100 from the connect versions). Mysql itself is only
          capable of 1024 connections (or at least ours crashes if I try to set the
          limit higher). So it stops working."

            be careful lots of freeware out there uses pconnect(), (ie. Phorum.org)

              Well, yeah, if you're using a host somewhere else. I code a lot for the corporate intranet at work... I use pconnect... I don't have any problems because we've got about 200 users using things at one time, the server has three databases in it, and each one keeps at max 20 connections open per database. 60 connections total, and it's faster and less expensive as far as server time to just maintain the connections.

              Like everything else, use pconnect or connect as your situation allows... don't trust anyone's blanket descriptions or condemnations.

                • [deleted]

                Just be carefull that PHP's pconnect implementation (and indeed the whole concept) is wonky at best.

                There was a discussion about this a week or so back.

                Connections don't just stay open, the entire state of the database is maintained. That means that in some cases the second script that uses the same connection scan read data that was generated by the first that used that connection. With MySQL's new transaction support I shudder to think that will happen....

                If you don't need pconnect for performance, the don't use it.

                  • [deleted]

                  You're right, the pconnect really could get ...interesting... when you're using innodb and doing funky table locks. 🙂

                    Write a Reply...