While digging through some old code put together by a former co-worker who's talents I looked up to I noticed after every query they closed the connection the MySQL server.
This seems a bit odd since I've always just closed it at the end of the page and seen most people do the same.
So the question is, is this the best idea in PHP/MySQL? Does it even matter one way or the other? The site this is running on has only about 100 users active on it at any given point throughout the day. So I can't see any real impact it would have one way or the other, but maybe it would make sense for a larger site?
解决方案
This can be helpful when working on an application that needs to scale to many concurrent users. By doing this, you only have the connection open for as short of a time as possible (ie, only when you are using it).
If you had 500 concurrent requests, they would be able to dovetail better so that one request could be doing computation on the PHP side while another was blocking on the database access.