too many connections - but only when fabricating a sitemap

Discussion in 'PHP' started by miko67, Jan 8, 2007.

  1. #1
    I stumbled over this question:
    over in this thread and it got me thinking...

    I have a directory with a few thousand pages. Every time I try to generate a sitemap with - well just about any sitemap generator there is - I end up with this very same problem.

    In my Site-Sift directory there is a build-in sitemap generator that uses (so I believe) the connection.php file to open the database for querying.
    Could this be changed to only open it once and then stay open for a time period... or is this really a stupid question?

    /miko67
     
    miko67, Jan 8, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes, you can use mysql_pconnect() instead of mysql_connect() for a persistent connection that stays open.
     
    rodney88, Jan 8, 2007 IP
  3. brunozugay

    brunozugay Peon

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why not use caching?
     
    brunozugay, Jan 9, 2007 IP
  4. miko67

    miko67 Well-Known Member

    Messages:
    769
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Good question... I have no idea how to. Anyone got a pointer in the right direction?

    /miko67
     
    miko67, Jan 10, 2007 IP
  5. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #5
    how long keeps mysql_pconnect() the connection open? some x secs/mins or until it reaches the end of the script?
     
    falcondriver, Jan 10, 2007 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    they may not be the way to go, firstly you need to find out if you have php running as an apache module or as a cgi binary, if you're running php in cgi mode theres no point using persistant connections as the php process is killed regardless of what's in it when the script stops executing, so the database connection will also be killed.

    I'm not sure exactly how long the connection stays available, I suppose it depends on the system you're using and how long a process can idle for but mostly if used in the right conditions it can certainly have a very positive effect of performance.

    If you go down the pconnect road make sure you read about it properly, you need to make sure that database connections are handled correctly, messy code and practice will ruin the advantages it has.
     
    krakjoe, Jan 10, 2007 IP
    falcondriver likes this.