public function __destruct() { if (!empty($this->pidfile) && file_exists($this->pidfile)) { if (!unlink($this->pidfile)) { Log::warning("Could not delete pid file " . $this->pidfile); } } }
/** * Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a MySQLi_Result object. For other successful queries mysqli_query() will return TRUE. */ public function query($sql) { $this->lastSql = $sql; $begin = intval(microtime(true) * 1000000); $this->connect(); $res = $this->mysqli->query($sql); #reconnect max times 3 for ($i = 0; $i < 3; $i++) { if (in_array($this->mysqli->errno, $this->retryErrno)) { Log::warning("db reconnect. [errno:" . $this->mysqli->errno . " error:" . $this->mysqli->error . " sql:{$sql}]"); usleep(100000); $this->connect(true); $res = $this->mysqli->query($sql); } else { break; } } if (false === $res) { Log::warning("db error. [errno:" . $this->mysqli->errno . " error:" . $this->mysqli->error . " sql: {$sql}]"); } $this->lastCost = intval(microtime(true) * 1000000) - $begin; $this->totalCost += $this->lastCost; if ($this->profile) { Log::debug('query success. [cost: ' . $this->lastCost . 'us] [sql: ' . $sql . ']'); } return $res; }