/    Sign up×
Community /Pin to ProfileBookmark

a few questions concerning mysql_pconnect

Hello

I have been reading about mysql_pconnect (persistent connections) and I am a bit confused from the problems they seem to cause people.

Here is what I understand:
If I use mysql_pconnect instead of mysql_connect, then used connections from the same host, username & password will not be thrown away after the child process of the web server (I am using Apache) is done with them. They will persist for a whlie before being garbaged.
This allows the child process to continue using the same connection if another request is made to the same host, username & password and the connection was still alive.

I understand that many people are complaining that the number of persistent connections keep getting larger and larger.
This is because the Web server spawns many child processes and each has its own connection.

Here is my question:
I all of the connections will be made to the same, username & password, can that problem still occur?

I also understand that MySQL can limit the number of open connections. Is there a way to tell it not to limit it and what the cosequences of that would be?

thanks in advance

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreApr 21.2004 — If all of the connections use pconnect and the exact same parameters, then no more connections will be created, the first one will just be reused.

To change the maximum number of connections there are two variables in the my.cnf MySQL file that affect this, max_connections is global and max_user_connections affects the different users that you add to the databases seperately. If you're using PHP to connect you need to edit php.ini, mysql.max_persistent and mysql.max_links for the maximum persistent and total connections.

The other consideration is that mysql_pconnect takes slightly longer to connect than mysql_connect, because it is creating the link for other processes to use. However, if your host has disabled persistent connections or has compiled PHP as a CGI "wrapper" then it will not be a persistent connection so you will actually waste more resources.
×

Success!

Help @davidklonski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...