Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should i use mysql persistent connect?

Tags:

php

mysql

The situation is: I have one Debian Server running LAMP with one Virtual Host with one Website. My MySQL has only one user from that website.

In this case would I benefit from using a persistent connection?

The PHP documentation seems to advise against persistent connections in any case.

Thanks


Edit: Yes, the MySQL server is on the same machine.

like image 261
dynamic Avatar asked Mar 16 '11 08:03

dynamic


People also ask

What are the disadvantages of using persistent connection in PDO?

The biggest drawback to persistent connections is that it limits the number of users you can have browsing your site: if MySQL is configured to only allow 10 concurrent connections at once then when an 11th person tries to browse your site it won't work for them. PDO does not manage the persistence.

What is MySQL persistent connection?

Persistent connections are links that do not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it.

What is the benefit of using persistent database connections in PHP?

The persistent connection cache allows you to avoid the overhead of establishing a new connection every time a script needs to talk to a database, resulting in a faster web application.

How long do MySQL connections last?

By default, the server closes the connection after 8 hours or 28800 seconds if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld via your server's /etc/my. cnf [...] If you don't see wait_timeout, just add it.


1 Answers

There's a discussion here http://groups.google.com/group/comp.databases.mysql/browse_thread/thread/4ae68befe1b488e7/e843f0b9e59ad710?#e843f0b9e59ad710 :

"No, it is not (better). Contrary, using mysql_pconnect() is considered harmful, as it tends to hog the MySQL server with idle connections."

If you connect via 'localhost', the connection will automatically be established via the MySQL socket, which is really cheap anyways.

(Groups link taken from MySQL Persistent Connections)

like image 59
konsolenfreddy Avatar answered Oct 03 '22 05:10

konsolenfreddy