MySQL persistent connections and advantages of mysql_pconnect?

后端 未结 2 511
感情败类
感情败类 2021-01-12 11:14

I had never heard of persistent connections before, and I don\'t understand the advantages.

I run a PHP/MySQL based website, it receives tens of thousands of page vi

相关标签:
2条回答
  • 2021-01-12 11:34

    Check out this URL:

    http://us3.php.net/manual/en/function.mysql-pconnect.php

    Basically mysql_pconnect() tries to find a persistent connection already open with the credentials that you've specified. If it doesn't find one it makes a new one. It also doesn't close the connection after a statement is executed

    So really in your case you may not notice a difference but in reality you should probably be using mysql_pconnect().

    0 讨论(0)
  • 2021-01-12 11:46

    Using a persistent connection leaves the connection open after the script has finished executing. Opening and closing connections over and over causes overhead, while small, that will eventually mount up as the number of requests go up.

    However, if you read the manual page for mysql_pconnect it states:

    • If PHP and MySQL are on the same server or local network, the connection time may be negligible, in which case there is no advantage to persistent connections.

    If this is the case it may not be worth the trouble changing your code.

    You can find more detailed information on persistent connections at the same site as above.

    0 讨论(0)
提交回复
热议问题