Persistent Connections
You can switch to persistent connections
in MySQL
by changing the function call from mysql_connect()
to mysql_pconnect()
. They both take the same parameters, with the difference being that mysql_connect()
will always open a new connection, whereas mysql_pconnect()
will open a new connection only if there is not one already available. Otherwise, it will just use the existing connection. Similarly, the SQLite function sqlite_open()
has a persistent counterpart, sqlite_popen()
.
Warning
In the per-process Apache module (prefork
), persistent resources such as persistent MySQL connections are stored per process. This means if you have 150 Apache children running, you'll need 150 MySQL permanent connectionsâeven if some of those processes aren't using MySQL right now.
Get PHP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.