Fwd: Fwd: [PHP-DB] MySQLi not closing connections

2008-11-26 Thread Fergus Gibson
-- Forwarded message --
From: Fergus Gibson [EMAIL PROTECTED]
Date: Wed, Nov 26, 2008 at 11:34 AM
Subject: Re: Fwd: [PHP-DB] MySQLi not closing connections
To: Chris [EMAIL PROTECTED]


On Tue, Nov 25, 2008 at 1:39 PM, Chris [EMAIL PROTECTED] wrote:
 Not really true.

 pconnect leaves the connection open ('persistent'). From the manual: when
 connecting, the function would first try to find a (persistent) link that's
 already open with the same host, username and password.

Here's a citation from Zend.com:

The mysql_pconnect() function was designed to provide a mechanism for
reducing the cost of establishing and closing connections to the MySQL
server. Unfortunately, due to an interaction between the architecture
of the Apache server and the architecture of PHP, high traffic on a
site that used pconnects could quickly clog up the MySQL server with
many unused connections that could prevent many of the active
connections from accessing the database.

http://devzone.zend.com/node/view/id/686#fn1

I understand how mysql_pconnect() is meant to work, which is what you
quote from the documentation, but I also believe the claims that there
is an incompatibility between Apache specifically and
mysql_pconnect().

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Fwd: [PHP-DB] MySQLi not closing connections

2008-11-26 Thread Fergus Gibson
-- Forwarded message --
From: Fergus Gibson [EMAIL PROTECTED]
Date: Wed, Nov 26, 2008 at 11:50 AM
Subject: Re: [PHP-DB] MySQLi not closing connections
To: Jonathan Langevin [EMAIL PROTECTED]


On Wed, Nov 26, 2008 at 10:36 AM, Jonathan Langevin
[EMAIL PROTECTED] wrote:
 I would normally think there were problems elsewhere in the code, if
 the issues didn't stop once I comment out the logging functionality.

I don't see anything that would account for your symptoms in that code
snippet, but it's important to remember that sometimes code in one
place can interact with code in another place to expose a bug.  When
your application uses ext/mysql, it uses only built-in functions.
It's only when it uses ext/mysqli that it uses a customized sub-class.
 I would look in that subclass for the problem.

But honestly, I'm flummoxed, Jon.  Since non-persistent connections
should automatically close when the script ends (normally or for an
error), I don't understand why the connections are remaining open only
when logging is enabled.  I would expect it to be a by-product of the
connection process instead or a bug.

Does the application use mysql_real_connect() or mysqli_real_connect()
at all?  If so, are you using a version of PHP pre-5.3?  There is a
bug and a bug fix for it.

http://bugs.mysql.com/bug.php?id=33831
http://bugs.php.net/bug.php?id=39457

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Fwd: [PHP-DB] MySQLi not closing connections

2008-11-25 Thread Fergus Gibson
Darn it.  Didn't change the e-mail recipient to be the list.


-- Forwarded message --
From: Fergus Gibson [EMAIL PROTECTED]
Date: Tue, Nov 25, 2008 at 12:02 PM
Subject: Re: [PHP-DB] MySQLi not closing connections
To: Jonathan Langevin [EMAIL PROTECTED]


On Tue, Nov 25, 2008 at 6:31 AM, Jonathan Langevin
[EMAIL PROTECTED] wrote:
 The problem is, this activity log, when enabled, results in all MySQL
 connections being used, and we run out of open connections. I'm not
 sure where the error is.

 Our config.php, when included, initializes the MySQL or MySQLi
 connection as decided by the script that included the config.
[...]

Hi, Jon.  It's difficult to offer specific replies without specific
code, but I did raise my eyebrow at the notion of mixing the mysql and
mysqli extensions in your application.  I'm guessing you've inherited
some pretty messy code that is time-consuming to refactor.

Is any of the code working against the mysql extension calling
mysql_pconnect() to create a persistent database connection?
Connections so opened CANNOT be closed using mysql_close().

I have never written an application using persistent connections, but
I did get hired at a company where the other programmers describe the
same problem you're having (a proliferation of connections that
overwhelmed the server).  They blamed mysql_pconnect() and the lead
programmer said that after he banned the use of that function, the
problem went away completely.  A comment to the PHP documentation
suggests this is the result of a bad interaction between Apache and
PHP.


 Within the same file, a shutdown function is registered to
 automatically close the MySQL or MySQLi connection at the end of
 script execution (based on which connection was initialized to begin
 with).

This should not be necessary.  The script will close all open
resources when it terminates anyway.  The reason for having and using
close functions is to free resources while the script is still
running.  As mentioned above, persistent connections created by
mysql_pconnect() cannot be closed by mysql_close() under any
circumstances, nor will they automatically close on completion of the
script.  I believe that's your problem.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Fwd: [PHP-DB] MySQLi not closing connections

2008-11-25 Thread Chris



I have never written an application using persistent connections, but
I did get hired at a company where the other programmers describe the
same problem you're having (a proliferation of connections that
overwhelmed the server).  They blamed mysql_pconnect() and the lead
programmer said that after he banned the use of that function, the
problem went away completely.  A comment to the PHP documentation
suggests this is the result of a bad interaction between Apache and
PHP.


Not really true.

pconnect leaves the connection open ('persistent'). From the manual: 
when connecting, the function would first try to find a (persistent) 
link that's already open with the same host, username and password.


If you're on a shared host with lots of different mysql 
username/passwords floating around, pconnect will be a very bad idea - 
because you'll end up with lots of connections sitting around doing 
nothing (and never being re-used).


If you're on dedicated hardware, pconnect can cut down the connection 
time - but when using them, you need to tune apache as well.


There's lots of notes here:

http://www.php.net/manual/en/features.persistent-connections.php

--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php