Zend Framework

connection control not sufficient in case of "Too many open links".

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.6.0RC2
  • Fix Version/s: 1.8.2
  • Component/s: Zend_Db_Adapter_Mysqli
  • Labels:
    None

Description

On Zend/Db/Adapter/Mysqli.php, around line 302 :
@$this->_connection = new mysqli(
$this->_config['host'],
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname'],
$port
);
if ($this->_connection === false || mysqli_connect_errno()) {
....
}

I'm using this, but I'm using too many links at the same time (the error that mysqlclient is returning is "Too many open links". BUT $this->_connection is not false (new mysqli() is returning mysqli Object ( ) as if everything was OK), and mysqli_connect_errno() does not return anything.

There should be a better control to check whether the connection is absolutely perfect or not. I personnaly think that this may be a PHP bug (new mysqli() should return false), but I posted it here in case.

php.ini config, related to Mysqli :
[mysqli]
mysqli.max_links = 3
mysqli.reconnect = On

Issue Links

Activity

Hide
Olivier Doucet added a comment -

I made some additional tests.

When the connection is OK, new mysqli() is returning a mysqli Object().
When the error appears, the same object is returned, but cannot be used. Example :

real_escape_string() [function.mysqli-real-escape-string]: Couldn't fetch mysqli in Zend/Db/Adapter/Mysqli.php on line 114

Show
Olivier Doucet added a comment - I made some additional tests. When the connection is OK, new mysqli() is returning a mysqli Object(). When the error appears, the same object is returned, but cannot be used. Example : real_escape_string() [function.mysqli-real-escape-string]: Couldn't fetch mysqli in Zend/Db/Adapter/Mysqli.php on line 114
Hide
Sébastien Vanvelthem added a comment -

I can confirm this issue at least on PHP 5.2.6 / Linux. As you said it happens only when the connection is not effective (failed because database not reachable, invalid login...). I don't agree with you on the fact that this is probably a PHP MySQLi related issue.

The problem is that when calling Zend_Db_Adapter_MySQLi::_connect(), we forget to unset the problematic mysqli object, let's see in ZF1.7.1 ::

if ($this->_connection === false || mysqli_connect_errno()) { require_once 'Zend/Db/Adapter/Mysqli/Exception.php'; throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); }

Patched version

if ($this->_connection === false || mysqli_connect_errno()) { // THE connection error was given with mysqli_connect_errno, the value of $this->_connection is a "invalid" mysqli object. So I reset it $this->_connection = false; require_once 'Zend/Db/Adapter/Mysqli/Exception.php'; throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); }

I'll post a separate bug report for this issue, hope this solution works

Thanks

Seb

Show
Sébastien Vanvelthem added a comment - I can confirm this issue at least on PHP 5.2.6 / Linux. As you said it happens only when the connection is not effective (failed because database not reachable, invalid login...). I don't agree with you on the fact that this is probably a PHP MySQLi related issue. The problem is that when calling Zend_Db_Adapter_MySQLi::_connect(), we forget to unset the problematic mysqli object, let's see in ZF1.7.1 :: if ($this->_connection === false || mysqli_connect_errno()) { require_once 'Zend/Db/Adapter/Mysqli/Exception.php'; throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); } Patched version if ($this->_connection === false || mysqli_connect_errno()) { // THE connection error was given with mysqli_connect_errno, the value of $this->_connection is a "invalid" mysqli object. So I reset it $this->_connection = false; require_once 'Zend/Db/Adapter/Mysqli/Exception.php'; throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); } I'll post a separate bug report for this issue, hope this solution works Thanks Seb
Hide
Satoru Yoshida added a comment -

Is this still active?
The description seems to be outdated.

Show
Satoru Yoshida added a comment - Is this still active? The description seems to be outdated.
Hide
Satoru Yoshida added a comment -

Solved in SVN r15598

Show
Satoru Yoshida added a comment - Solved in SVN r15598

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: