I'm currently running 2 different scripts for one site. A video script and a link dump script. When a page loads for the first time (and only the first time), I do the following: 1.) I close out the connection to the video DB 2.) I connect to the link dump DB and record "hits in" if appropriate 3.) I then close out the connection to the link dump DB 4.) I reconnect to the video DB Is this ok? I don't want to hit a concurrent connections limit or anything. Also, do you think it's overkill to close out the video DB and reconnect each time? Any help would be greatly appreciated.
Unless the connection took a long time, I would not close out the first connection. I would do this: Open 1 and 2; //do stuff Close 2; Close 1;
I agree with step, but want to add a note. Acquire your resources late, consume as needed, and close resource. If you need to connect to multiple MySQL databases that is fine, no problem.
If the page load is still fast leave them open. When the document ends and the page is shown the connections are closed anyways. Only reopened when a new page is opened calling the connection again. php automatically closes the DB at the end of a document. TJ
I explicitly close connections. Leaving connections open and relying on the end of script to close your database connections is bad practice. Never leave connections open or objects hanging around consuming resources. You can pool database connections as needed to minimize the overhead of opening a new connection.
I was making ref. to small scripts that do not take much time to load. yes its in good practice to close all connections at the end of running a script. However by default they are closed upon ending the script execution. TJ