#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    PHP Keeps MySQL Connection Alive


    Hello guys,

    Is it possible to keep MySQL connection alive even after the end of PHP scripts? I want only to connect once and keep the connection active for "X" minutes.

    Thank you.
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,761
    Rep Power
    9397
    Yes but you very rarely should. There are penalties for doing so.

    Are you having a problem?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0
    Originally Posted by requinix
    Yes but you very rarely should. There are penalties for doing so.

    Are you having a problem?
    I want to execute mysql_connect and mysql_select_db only once and then run mysql_query for the queries...
    Can you provide any solution for keeping alive the connection? I tried wait_timeout and interactive_timeout but this only works in MySQL console. In php the connection automatically close once the script ends.

    Thank you
  6. #4
  7. Banned
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,938
    Rep Power
    0
    Hi,

    since requinix' warning obviously wasn't clear enough: Do not use persistent connections unless you really, truly know what you're doing.

    Managing persistent connections isn't trivial. You have to know exactly what the risks and benefits are, and you should have a very good reason for using them. Vague assumptions like "I think they're more efficient" is not a good reason.

    The question is: What problem are you trying to solve? What's your actual goal?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    since requinix' warning obviously wasn't clear enough: Do not use persistent connections unless you really, truly know what you're doing.

    Managing persistent connections isn't trivial. You have to know exactly what the risks and benefits are, and you should have a very good reason for using them. Vague assumptions like "I think they're more efficient" is not a good reason.

    The question is: What problem are you trying to solve? What's your actual goal?
    SOLVED

    Comments on this post

    • Jacques1 disagrees : Solved how? Please don't close your threads, often times people have additional comments or better solutions.

IMN logo majestic logo threadwatch logo seochat tools logo