If I have a script which inserts data then exits, the script will be opened by 100 users at the same time or within 2 mins.
(Actually I'm doing email tracking.)
So pconnect is better, or connect is better to reduce the resource?
I have close when after insert.
Establishes a persistent connection to a MySQL server. mysql_pconnect() acts very much like mysql_connect() with two major differences. First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password.
mysqli_pconnect() function is depreciated in the new version of PHP, but you can create persistence connection using mysqli_connect with the prefix p.
Mysqli_connect Vs Mysql_connect? mysqli_* functions are used with a mysqli_connect resource and mysql_* functions are used with a mysql_connect resource. mysqli has more features and is the more current version to use. you may also want to look into PDO which is an OO way of connecting to databases.
mysql_pconnect()
drops the open connection into a pool that can be used by any other request to the same process. As such, each worker keeps the connection open until it dies. This can be acceptable if you keep the number of workers low, but as soon as you raise the number of workers then you're better off switching to mysql_connect()
. It will take slightly longer per request since the connection has to be made each time, but you will only create as many connections as there are requests, not workers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With