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
Yes, you can use mysql_pconnect() instead of mysql_connect() for a persistent connection that stays open.
how long keeps mysql_pconnect() the connection open? some x secs/mins or until it reaches the end of the script?
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.