title: mysql connections. Should I keep it alive or start a new connection before each transaction?
body: <p>I'm doing my first foray with mysql and I have a doubt about how to handle the connection(s) my applications has.</p>
  
  <p>What I am doing now is opening a connection and keeping it alive until I terminate my program. I do a mysql_ping() every now and then and the connection is started with MYSQL_OPT_RECONNECT.</p>
  
  <p>The other option (I can think of), would be to start a new connection before doing anything that requires my connection to the database and closing it after I'm done with it.</p>
  
  <p>What are the pros and cons of these two approaches?
  what are the "side effects" of a long connection? 
  What is the most used method of handling this?</p>
  
  <p>Cheers ;)</p>
  
  <hr>
  
  <p>Some extra details</p>
  
  <p>At this point I am keeping the connection alive and I ping it every now and again to now it's status and reconnect if needed.</p>
  
  <p>In spite of this, when there is some consistent concurrency with queries happening in quick succession, I get a "Server has gone away" message and after a while the connection is re-established.</p>
  
  <p>I'm left wondering if this is a side effect of a prolonged connection or if this is just a case of bad mysql server configuration.</p>
  
  <p>Any ideas?</p>