Changeset 1059 for trunk/common
- Timestamp:
- 11/04/09 00:52:17 (3 years ago)
- File:
-
- 1 edited
-
trunk/common/db/db_mysql.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/db/db_mysql.php
r930 r1059 8 8 log_assert(!isset($dbLink), "Already connected to the database."); 9 9 10 // log_print(" connecting to database");10 // log_print("Connecting to database..."); 11 11 if (!$dbLink = @mysql_connect(IA_DB_HOST, IA_DB_USER, IA_DB_PASS)) { 12 log_error('Cannot connect to database: '.mysql_error()); 12 if (IA_DB_KEEP_ALIVE) { 13 $timeout = 0; 14 do { 15 log_warn('Cannot connect to database: '.mysql_error(). 16 "\nRetrying..."); 17 18 // Wait for an increasing amount of seconds to avoid 19 // strain on the mysql server if it is under heavy load 20 sleep($timeout); 21 $timeout = min(max(1, $timeout * 2), 60); 22 23 // Try and reconnect to the database server 24 $dbLink = @mysql_connect(IA_DB_HOST, IA_DB_USER, IA_DB_PASS); 25 } while (!db_isalive()); 26 log_print('Connected to database.'); 27 } else { 28 log_error('Cannot connect to database: '.mysql_error()); 29 } 13 30 } 14 31 if (!mysql_select_db(IA_DB_NAME, $dbLink)) { … … 16 33 } 17 34 mysql_query('SET NAMES utf8'); 35 return true; 18 36 } 19 37 … … 35 53 return false; 36 54 } 37 while (!db_isalive()) { 38 if (is_resource($dbLink)) { 39 mysql_close($dbLink); 40 } 41 $dbLink = null; 42 db_connect(); 43 // Wait for 1 second 44 sleep(1); 55 if (is_resource($dbLink)) { 56 mysql_close($dbLink); 45 57 } 46 return true; 58 59 return db_connect(); 47 60 } 48 61
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)