Re: [phplib-dev] db_mysql.inc & pconnect From: Maxim Derkachev (max.derkachev <email protected>)
Date: 05/18/01

Hello Holger,

Friday, May 18, 2001, 5:21:05 PM, you wrote:

HB> how can i handle mysql pconnects without the behaivor that iŽll receive
HB> a new persistent connection with every new page/query ?

Then you receive a new httpd daemon with every new page/query.
Pconnect make a persistent connection for a process (httpd in our
case). It is reused with the next page served by the process.
If you have, say, 100 simultaneously running httpd processess, and
every one of them once used pconnect, you'll have 100 connection
tuples to the db. When a process dies (for any reason), the pconnect
it held is also dropped.

HB> $db = new example_DB("SELECT id, username FROM members ".
HB> "WHERE user_id = '".$auth->auth["uid"]."'");

HB> do i have to provide a Link ID ?
HB> In session and auth, isnŽt done this automatically ?

PHP knows the resource of db connection you're currently use. If a
connection has made, it will be reused by subsequent queries. If the
connection is dead, only connect or pconnect could help. So the link
id is not obligatory - PHP module itself will provide it.

HB> i changed the pconnect to connect in db_mysql.inc because otherwise, after
HB> a short while, clients receive "too many connections" from the mysql
HB> daemon.

So you have the limit of connections set to insufficient value.
Connect is also reused by PHP, while it is alive - if you call connect
in one script, say, twice, and do not call close before the second
connect, only the first connect will actually establish a db connection -
others will see that we have an alive connection, and won't try further.
The only reason between connect and pconnect is that pconnect survives
the script shutdown, while connect does not.
Very often it is more wise to use connect instead of pconnect - you'll
have some connection overhead, but the number of unused connections to
the db will be close to 0, which will save you a lot of RAM. Pconnect
IMHO is only useful if all the httpd processes on you server being
very busy all the time.

-- 
Best regards,
Maxim Derkachev mailto:max.derkachev <email protected>
System administrator & programmer,
Symbol-Plus Publishing Ltd.
phone: +7 (812) 324-53-53
www.books.ru, www.symbol.ru 

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected> For additional commands, e-mail: phplib-dev-help <email protected>