mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
* support for database persistent and socket connections (performance boost)
This commit is contained in:
parent
adbec47fad
commit
510459b046
@ -64,6 +64,8 @@ $config = array(
|
||||
'database_password' => '',
|
||||
'database_name' => '',
|
||||
'database_log' => false, // should database queries be logged and displayed in the page source? They will be included at the end of the .html source of the page
|
||||
'database_socket' => '', // set if you want to connect to database through socket (example: /var/run/mysqld/mysqld.sock)
|
||||
'database_persistent' => false, // use database permanent connection (like server), may speed up your site
|
||||
|
||||
// multiworld system (only TFS 0.3)
|
||||
'multiworld' => false, // use multiworld system?
|
||||
|
@ -9,7 +9,7 @@
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
if(!isset($config['database_type'][0], $config['database_user'][0], $config['database_password'][0], $config['database_name'][0]))
|
||||
if(!isset($config['database_user'][0], $config['database_password'][0], $config['database_name'][0]))
|
||||
{
|
||||
if(isset($config['lua']['sqlType'])) {// tfs 0.3
|
||||
if(isset($config['lua']['mysqlHost'])) {// tfs 0.2
|
||||
@ -45,6 +45,9 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$config['database_user'] = $config['lua']['mysqlUser'];
|
||||
$config['database_password'] = $config['lua']['mysqlPass'];
|
||||
$config['database_name'] = $config['lua']['mysqlDatabase'];
|
||||
if(!isset($config['database_socket'][0])) {
|
||||
$config['database_socket'] = isset($config['lua']['mysqlSock']) ? trim($config['lua']['mysqlSock']) : '';
|
||||
}
|
||||
$config['database_encryption'] = 'sha1';
|
||||
}
|
||||
else if(isset($config['lua']['database_type'])) // otserv
|
||||
@ -80,13 +83,19 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
$config['database_log'] = false;
|
||||
}
|
||||
|
||||
if(!isset($config['database_socket'])) {
|
||||
$config['database_socket'] = '';
|
||||
}
|
||||
|
||||
try {
|
||||
$ots->connect(array(
|
||||
'host' => $config['database_host'],
|
||||
'user' => $config['database_user'],
|
||||
'password' => $config['database_password'],
|
||||
'database' => $config['database_name'],
|
||||
'log' => $config['database_log']
|
||||
'log' => $config['database_log'],
|
||||
'socket' => @$config['database_socket'],
|
||||
'persistent' => @$config['database_persistent']
|
||||
)
|
||||
);
|
||||
|
||||
@ -96,7 +105,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
||||
if(isset($cache) && $cache->enabled()) {
|
||||
$cache->delete('config_lua');
|
||||
}
|
||||
|
||||
|
||||
if(defined('MYAAC_INSTALL')) {
|
||||
return; // installer will take care of this
|
||||
}
|
||||
|
@ -64,16 +64,6 @@ class OTS_DB_MySQL extends OTS_Base_DB
|
||||
$params['port'] = $host[1];
|
||||
}
|
||||
|
||||
if( isset($params['host']) )
|
||||
{
|
||||
$dns[] = 'host=' . $params['host'];
|
||||
}
|
||||
|
||||
if( isset($params['port']) )
|
||||
{
|
||||
$dns[] = 'port=' . $params['port'];
|
||||
}
|
||||
|
||||
if( isset($params['database']) )
|
||||
{
|
||||
$dns[] = 'dbname=' . $params['database'];
|
||||
@ -99,6 +89,10 @@ class OTS_DB_MySQL extends OTS_Base_DB
|
||||
$this->logged = true;
|
||||
}
|
||||
|
||||
if( !isset($params['persistent']) ) {
|
||||
$params['persistent'] = false;
|
||||
}
|
||||
|
||||
global $cache, $config;
|
||||
if(isset($cache) && $cache->enabled()) {
|
||||
$tmp = null;
|
||||
@ -123,7 +117,27 @@ class OTS_DB_MySQL extends OTS_Base_DB
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct('mysql:' . implode(';', $dns), $user, $password);
|
||||
if(isset($params['socket'][0])) {
|
||||
$dns[] = 'unix_socket=' . $params['socket'];
|
||||
|
||||
parent::__construct('mysql:' . implode(';', $dns), $user, $password, array(
|
||||
PDO::ATTR_PERSISTENT => $params['persistent']
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( isset($params['host']) ) {
|
||||
$dns[] = 'host=' . $params['host'];
|
||||
}
|
||||
|
||||
if( isset($params['port']) ) {
|
||||
$dns[] = 'port=' . $params['port'];
|
||||
}
|
||||
|
||||
parent::__construct('mysql:' . implode(';', $dns), $user, $password, array(
|
||||
PDO::ATTR_PERSISTENT => $params['persistent']
|
||||
));
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
|
Loading…
x
Reference in New Issue
Block a user