tags:

views:

120

answers:

3

I read specifications of mysql_pconnect of the function of PHP.. "mysql_pconnect is that connection with the SQL server is not closed even if the practice of the script is finished".

There is it unless connection is closed, but will it be that connection stays until a timing of the reboot of mysql?

A: 

yes, but you can not close it using mysql___close.

It will close when you reboot mysql server, or when the connection stays idle (not used) for a specific amount of time, defined in the configuration variable wait_timeout.

Aziz
+1  A: 

I think, and I may be wrong, but...

I think the pconnect is a persistant connection held not for the running of the script, but for the duration of the PHP session / MySQL session, that there is a socket connection maintained by PHP regardless of the which script is being run. A bit like having multiple documents open in word instead of multiple instances of notepad running. by using a common database link, the processing power for creating individual links is not needed.

However, after reading, I think that it only seems to be of benefit if PHP is being run as an Apache module, not in CGI mode.

Call me out on my misinformation.

Assembler
+1  A: 

mysql_pconnect allows Apache's mod_php module to do connection pooling. You can still call mysql_close, but mod_php will not actually close it; it will just invalidate your resource handle. Unfortunately, the module doesn't have any configuration for this, so pooled connections are reaped by the MySQL server via its wait_timeout parameter. The default value of this is quite high so if you want to take advantage of it, you will probably want to lower that variable.

Connection pooling saves two things: connection setup and MySQL thread creation. Connection setup is very fast with MySQL compared to other databases, but a highly in-demand web site could still see a benefit from reducing this step. The cost of thread creation in MySQL is more dependant on the underlying OS but it can still be a win for a busy site.

Both aspects need to be looked at in the bigger picture of website speed and the load it presents on your database. It is possible to run out of connection threads on the database with a busy enough site using connection pooling. There is also the aspect that your application needs to do its best to leave the connection in a consistent state, as you can no longer rely on closing the connection to do things like unlock tables and rollback transactions.

There is more information in the PHP documentation.

staticsan