E
E
ertaquo2011-04-20 10:00:15
PHP
ertaquo, 2011-04-20 10:00:15

Persistent connection in MySQL and memcache?

I want to try using a persistent connection in MySQL and memcache on my site, but before that, to be sure, I want to ask a couple of questions that I didn’t find the answer to in the documentation (although maybe I didn’t search well):
1. Mysql_pconnect / memcache_pconnect calls open new connections every time or use unclosed old ones? Will the same connection be used in parallel when executing two scripts, or can it be used by only one script at a time, and a new connection is opened for the second one?
2. Does this result in a real increase in application speed?
3. What are the pros and cons of this method?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2011-04-20
@ertaquo

1. they use the old ones
2. yes, there is an increase. exactly the amount of time that is spent on mysql_connect + mysql_select_db + "set names" (or whatever else you decide to do after each connection)
3. plus one - speed.
cons:
1. there is no way to forcibly close the connection.
2. Due to the saving of currently unnecessary connections, the memory of the mysql server is consumed.
3. Upon completion of the script, LOCK is not removed from tables and TEMPORARY tables are not destroyed.
4. you need to separately monitor mysql server has gone away =)
5. Apache's mod_php doesn't work well with pconnects. well, that is, in itself it works as it should, and from the point of view of the Apache it is not crooked. the pconnect logic itself just breaks down: a new worker spawns on a new request, which does not know about the neighbor's persistent connection, and opens a new one, slightly increasing the scale of the problem from point two.

A
Alexey Shein, 2011-04-20
@conf

Answer from the documentation in Russian: www.php.net/manual/ru/features.persistent-connections.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question