Jump to content

mysql connections in php application


Alex

Recommended Posts

I have a PHP application that is running from the CLI. This application will sometimes require a connection to a mysql database. I was wondering if I should create and close a new mysql connection every time I need to preform a query on the database, or if I should just keep one open throughout the entire duration of the program. If the latter I assume that because it's a single execution of the script (even though the duration will be very long periods of time) using a normal connection vs a persistent connection would have no effect.

Link to comment
Share on other sites

The only problem I can see with a long-lived connection is if your program isn't using it, i.e. it goes idle, the server may kill it.  You'd want your program to detect if the server has killed the connection and re-open it if it has.

 

Other than that I'm not sure it really matters.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.