Permalink
Browse files

Merge branch 'MDL-25910_20_wip_mysqlsocket' of git://github.com/skoda…

…k/moodle
  • Loading branch information...
2 parents e5654ca + 3c1293f commit dcad74e406c4f6bd89159252a004ea40a464dda1 Sam Hemelryk committed Jan 18, 2011
Showing with 18 additions and 6 deletions.
  1. +6 −3 config-dist.php
  2. +8 −2 lib/dml/mysqli_native_moodle_database.php
  3. +4 −1 lib/dml/pgsql_native_moodle_database.php
View
@@ -50,9 +50,12 @@
// used? set to 'false' for the most stable
// setting, 'true' can improve performance
// sometimes
- 'dbsocket' => false, // should connection via UNIX socket be
- // used? if you set it to 'true' here,
- // set dbhost to 'localhost'
+ 'dbsocket' => false, // should connection via UNIX socket be used?
+ // if you set it to 'true' or custom path
+ // here set dbhost to 'localhost',
+ // (please note mysql is always using socket
+ // if dbhost is 'localhost' - if you need
+ // local port connection use '127.0.0.1')
'dbport' => '', // the TCP port number to use when connecting
// to the server. keep empty string for the
// default port
@@ -264,15 +264,21 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dbop
}
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
- unset($this->dboptions['dbsocket']);
+ // dbsocket is used ONLY if host is NULL or 'localhost',
+ // you can not disable it because it is always tried if dbhost is 'localhost'
+ if (!empty($this->dboptions['dbsocket']) and strpos($this->dboptions['dbsocket'], '/') !== false) {
+ $dbsocket = $this->dboptions['dbsocket'];
+ } else {
+ $dbsocket = ini_get('mysqli.default_socket');
+ }
if (empty($this->dboptions['dbport'])) {
$dbport = ini_get('mysqli.default_port');
} else {
$dbport = (int)$this->dboptions['dbport'];
}
ob_start();
- $this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport);
+ $this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbsocket);
$dberr = ob_get_contents();
ob_end_clean();
$errorno = @$this->mysqli->connect_errno;
@@ -138,8 +138,11 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dbop
// Unix socket connections should have lower overhead
if (!empty($this->dboptions['dbsocket']) and ($this->dbhost === 'localhost' or $this->dbhost === '127.0.0.1')) {
$connection = "user='$this->dbuser' password='$pass' dbname='$this->dbname'";
+ if (strpos($this->dboptions['dbsocket'], '/') !== false) {
+ $connection = $connection." host='".$this->dboptions['dbsocket']."'";
+ }
} else {
- $this->dboptions['dbsocket'] = 0;
+ $this->dboptions['dbsocket'] = '';
if (empty($this->dbname)) {
// probably old style socket connection - do not add port
$port = "";

0 comments on commit dcad74e

Please sign in to comment.