persistent mySQL links

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
levik
Forum Newbie
Posts: 3
Joined: Thu Jun 27, 2002 6:34 pm

persistent mySQL links

Post by levik »

Hi. My scripts, are being hit fast and often, and I thought that a mySQL + PHP combo was the one to beat because of the possibility of using persistent DataBase connections.

However, I am not sure this is working as it should. In my code, I use the

Code: Select all

mysql_pconnect()
function, and my php.ini file has persistent links enables, and both persistent and regular link limit is set to -1 (Unlimited).

This is reflected when I do

Code: Select all

phpinfo()
so I know my configuration is being found and read. But the connection count on that same info page never goes above 1. I know that the scripts are being hit, and that the connections are being opened, but I have a sinking feeling that they are not kept open for later use. Or, (and this would be worse), all the instances of the script are forced to share one solitary connection, which means they are forced to wait on it.

Can anyone suggest something?
josa
Forum Commoner
Posts: 75
Joined: Mon Jun 24, 2002 4:58 am
Location: Sweden

Post by josa »

When you use persistent connections the open connections are supposed to get reused. This is one of the advantages of this type of connection. The MySQL manual gives this as an example of optimization, so I don't think the performance should suffer if you use them. Take a look at section 5.2.11 of the MySQL manual. You can also find some useful information if you look up mysql_pconnect() in the PHP docs.

/josa
levik
Forum Newbie
Posts: 3
Joined: Thu Jun 27, 2002 6:34 pm

Post by levik »

I understand the advantages of using persistent links. I just think that for some reason my setup is not working. I expected there to be more than one active connection for the amount of traffic that my script receives, since otherwise, all the instances of the script are waiting on one connection, slowing things down. But the phpinfo() screen never shows more than one connection active. Now I know php.ini allows you to configure maximum active links, and I have it set to unlimited, but the count never exceeds 1 anyway.
josa
Forum Commoner
Posts: 75
Joined: Mon Jun 24, 2002 4:58 am
Location: Sweden

Post by josa »

But it's supposed to show one connection because there is only one active connection. If you do multiple connects with mysql_pconnect() and with the same credentials, PHP will reuse the previously open connection. I don't think that the different requests have to wait for each other and even if they do, I don't think the performance will suffer. To summarize: your setup is working as expected.

/josa
levik
Forum Newbie
Posts: 3
Joined: Thu Jun 27, 2002 6:34 pm

Post by levik »

Hmmm... well, the thing is that it's not uncommon for me to have 5 simultaneous connection to the script open by different people. If all of these 5 people have to wait for each other to be done, then performance does suffer versus a case where they don't have to wait.

As I understand it, PHP only reuses a previously open persistent link if it is free to use, otherwise it should create a new one to avoid waiting. Who know how long the process that's using it will keep it for.
Post Reply