ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.3k stars 1.34k forks source link

BUG: could not auto reconnect in swoole #712

Open getchu opened 6 years ago

getchu commented 6 years ago

mysqli::prepare(): send of 102 bytes failed with errno=32 Broken pipe in file /Vendor/MysqliDb/MysqliDb.php line 1908 time : 18-01-15 09:14:54 message: Error while sending STMT_PREPARE packet. PID=1710 in file /Vendor/MysqliDb/MysqliDb.php line 1908

bug: connect timeout when execute some query in an thread for a long time .

getchu commented 6 years ago

file: MysqliDb.php method: _prepareQuery

$stmt = $this->mysqli()->prepare($this->_query); //BUG:trigger ERROR here and print buffer if ($stmt !== false) { if ($this->traceEnabled) $this->traceStartQ = microtime(true); return $stmt; } if ($this->mysqli()->errno === 2006 && $this->autoReconnect === true && $this->autoReconnectCount === 0) {

//BUG: where is "autoReconnectCount =0" ,so it will connect one time, and never reconnect again!

  $this->connect($this->defConnectionName);
  $this->autoReconnectCount++;
  return $this->_prepareQuery();

} $error = $this->mysqli()->error; $query = $this->_query; $errno = $this->mysqli()->errno;

VonHirsch commented 6 years ago

Note that autoReconnectCount is reset in reset() so it will try to connect once for each database operation.

I have created a fix for reconnect PR #793