Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php pconnect vs connect

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.

like image 261
user192344 Avatar asked Mar 14 '10 04:03

user192344


People also ask

What is Pconnect PHP?

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.

What is the difference between my SQL Connect and My SQL P connect?

mysqli_pconnect() function is depreciated in the new version of PHP, but you can create persistence connection using mysqli_connect with the prefix p.

What is the difference between mysql_connect and mysqli_connect?

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.


1 Answers

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.

like image 115
Ignacio Vazquez-Abrams Avatar answered Oct 16 '22 22:10

Ignacio Vazquez-Abrams