- Timestamp:
- Aug 15, 2020 11:16:58 PM (4 years ago)
- Location:
- trunk/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/App.inc.php
r732 r733 413 413 414 414 // DB connection parameters taken from environment variables in the server httpd.conf file (readable only by root)⊠415 if ( !empty($_SERVER['DB_SERVER']) && !$this->getParam('db_server')) {415 if (isset($_SERVER['DB_SERVER']) && '' != $_SERVER['DB_SERVER'] && null === $this->getParam('db_server')) { 416 416 $this->setParam(array('db_server' => $_SERVER['DB_SERVER'])); 417 417 } 418 if ( !empty($_SERVER['DB_NAME']) && !$this->getParam('db_name')) {418 if (isset($_SERVER['DB_NAME']) && '' != $_SERVER['DB_NAME'] && null === $this->getParam('db_name')) { 419 419 $this->setParam(array('db_name' => $_SERVER['DB_NAME'])); 420 420 } 421 if ( !empty($_SERVER['DB_USER']) && !$this->getParam('db_user')) {421 if (isset($_SERVER['DB_USER']) && '' != $_SERVER['DB_USER'] && null === $this->getParam('db_user')) { 422 422 $this->setParam(array('db_user' => $_SERVER['DB_USER'])); 423 423 } 424 if ( !empty($_SERVER['DB_PASS']) && !$this->getParam('db_pass')) {424 if (isset($_SERVER['DB_PASS']) && '' != $_SERVER['DB_PASS'] && null === $this->getParam('db_pass')) { 425 425 $this->setParam(array('db_pass' => $_SERVER['DB_PASS'])); 426 426 } -
trunk/lib/PDO.inc.php
r729 r733 81 81 'character_set' => '', 82 82 'collation' => '', 83 84 // Reconnection attempt limit. Set to 0 to disable retries, i.e., only the first connect will be attempted. 85 'retry_limit' => 8, 83 86 ); 84 87 … … 164 167 * @since 09 Jul 2019 08:16:42 165 168 */ 166 public function connect( )169 public function connect($retry_num=0) 167 170 { 168 171 $app =& App::getInstance(); … … 174 177 175 178 // If db_server not specified, assume localhost. 176 if ( !$this->getParam('db_server')) {179 if (null === $this->_params['db_server']) { 177 180 $this->setParam(array('db_server' => 'localhost')); 178 181 } … … 193 196 $this->dbh = new \PDO($dsn, $this->getParam('db_user'), $this->getParam('db_pass'), $options); 194 197 } catch (\PDOException $e) { 195 $mysql_error_msg = sprintf('PDO connect %s: %s (db_server=%s, db_name=%s, db_user=%s, db_pass=%s) ',198 $mysql_error_msg = sprintf('PDO connect %s: %s (db_server=%s, db_name=%s, db_user=%s, db_pass=%s)%s', 196 199 get_class($e), 197 200 $e->getMessage(), … … 199 202 $this->getParam('db_name'), 200 203 $this->getParam('db_user'), 201 ('' == $this->getParam('db_pass') ? 'NO' : 'YES') 204 ('' == $this->getParam('db_pass') ? 'NO' : 'YES'), 205 ($retry_num > 0 ? ' retry ' . $retry_num : '') 202 206 ); 203 $app->logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__); 207 // Use LOG_NOTICE for first connection attempts, and LOG_EMERG for the last one. 208 $app->logMsg($mysql_error_msg, ($retry_num >= $this->getParam('retry_limit') ? LOG_EMERG : LOG_NOTICE), __FILE__, __LINE__); 209 210 // These are probably transient errors: 211 // SQLSTATE[HY000] [2002] Connection refused 212 // SQLSTATE[HY000] [2002] No such file or directory 213 // SQLSTATE[HY000] [2006] MySQL server has gone away 214 if ($retry_num < $this->getParam('retry_limit') && (strpos($e->getMessage(), '[2002]') !== false || strpos($e->getMessage(), '[2006]') !== false)) { 215 // Try again after a delay: 216 usleep(500000); 217 return $this->connect(++$retry_num); 218 } 204 219 205 220 // Print helpful or pretty error? 206 221 if ($this->getParam('db_debug') && $app->getParam('display_errors')) { 207 222 if (!$app->isCLI()) { 208 printf('<pre style="padding:1em;background:#ddd;font: 0.9remmonospace;">%s</pre>', $mysql_error_msg);223 printf('<pre style="padding:1em;background:#ddd;font:10px monospace;">%s</pre>', $mysql_error_msg); 209 224 } 210 225 }
Note: See TracChangeset
for help on using the changeset viewer.