hi all experts.. I am developing an image hosting site, and while using mysql_connect(), I thought I must use mysql_pconnect() - WHY ? becuase I think this will be helpful if someone has added 50 images in one page and each image page connects to the database to store differnet types of data such as view, bandwidth, url etc, so mysql_connect() will open 50 connections but if I use mysql_pconnect() it will only open 1 connection.. Is that right ? shall I use mysql_pconnect()... what are the drawbacks of mysql_pconnect() and how this persistent connection closes ? do I have to do anything on my part ? please advise..
I think I have read that it is slightly faster and less intensive. I know you have to close the connection at some point in time.
If I'm not mistaken, mysql_connect would be fine to use. Why? When someone connects to the database, the user makes a single connection. This connection is used until the connection is closed at the end of the script, or at the footer. Inside this single connection, you could have the script parsing the exif info and what not from the image, get the filesize and insert into the db. When this information is called, you could have all that information on the same page as what viewer would see the image. That way, you only have one connection made per image upload and one per download, but multiple data fields submitted and called. My imageboard on my signature is not using pconnects and it only goes up to max 30 connections per second.
Both functions are correct by I recommend using mysql_connect(). The reason is both function reuse connections that were not previously closed using mysql_close (most developers don't close the connections using mysql_close because PHP closes them anyway after the script has ended execution. However, with mysql_pconnect the connections stay open for a longer time, with mysql_connect as far as i understand remain open for a few seconds only or something like that. From what I have read (I'm not sure right now that it's true) mysql_pconnect should not be used because some functions may return results from the previous script that used the connection. For example, if you're trying to insert something in the database and it fails and you're trying to use mysql_insert_id to get the last insert ID, the ID would actually be the ID of the INSERT query of the previous script that was executed, because your INSERT query has failed. Or something like that. So my belief is that mysql_pconnect would not cause a big advantage that would make it worth to have weird problems that are hard to debug.
Hi Maxell, Check out the PHP page about persistent connections at http://uk2.php.net/manual/en/features.persistent-connections.php Petey