|
|
@@ -17,6 +17,7 @@ class Mlogic
|
|
|
private static $redis = null;
|
|
|
private static $redisTime = null;
|
|
|
public static $global = null;
|
|
|
+ private static $configPath = null;
|
|
|
|
|
|
public static function GetInstance()
|
|
|
{
|
|
|
@@ -32,49 +33,53 @@ class Mlogic
|
|
|
|
|
|
private static function Init()
|
|
|
{
|
|
|
+ $mds = DIRECTORY_SEPARATOR;
|
|
|
+ if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
|
|
|
+ self::$configPath = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds;
|
|
|
+ } else {
|
|
|
+ self::$configPath = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds;
|
|
|
+ }
|
|
|
+
|
|
|
self::getDb();
|
|
|
self::getRedis();
|
|
|
self::getGlbData();
|
|
|
}
|
|
|
|
|
|
//workman 的共享数据插件
|
|
|
- public static function getGlbData()
|
|
|
+ public static function getGlbData($cache = 1)
|
|
|
{
|
|
|
- if (empty(self::$global)) {
|
|
|
- self::$global = new \GlobalData\Client('127.0.0.1:2207');
|
|
|
+ if ($cache) {
|
|
|
+ if (!empty(self::$global)) {
|
|
|
+ return self::$global;
|
|
|
+ }
|
|
|
}
|
|
|
+ self::$global = new \GlobalData\Client('127.0.0.1:2207');
|
|
|
return self::$global;
|
|
|
}
|
|
|
|
|
|
- public static function getDb()
|
|
|
+ public static function getDb($cache = 1)
|
|
|
{
|
|
|
- if (empty(self::$db)) {
|
|
|
- $mds = DIRECTORY_SEPARATOR;
|
|
|
- if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
|
|
|
- $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'database.php';
|
|
|
- } else {
|
|
|
- $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'database.php';
|
|
|
+ if ($cache) {
|
|
|
+ if (!empty(self::$db)) {
|
|
|
+ return self::$db;
|
|
|
}
|
|
|
- $conf = require($dbcfg);
|
|
|
- self::$db = new \Workerman\MySQL\Connection($conf['hostname'], $conf['hostport'], $conf['username'], $conf['password'], $conf['database']);
|
|
|
}
|
|
|
+
|
|
|
+ $conf = require(self::$configPath . 'database.php');
|
|
|
+ self::$db = new \Workerman\MySQL\Connection($conf['hostname'], $conf['hostport'], $conf['username'], $conf['password'], $conf['database']);
|
|
|
+
|
|
|
return self::$db;
|
|
|
}
|
|
|
|
|
|
//实例化redis
|
|
|
- public static function getRedis($force = 0)
|
|
|
+ public static function getRedis($cache = 1)
|
|
|
{
|
|
|
- if (!empty(self::$redis) && !$force) {
|
|
|
- return self::$redis;
|
|
|
- }
|
|
|
-
|
|
|
- $mds = DIRECTORY_SEPARATOR;
|
|
|
- if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
|
|
|
- $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'redis.php';
|
|
|
- } else {
|
|
|
- $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'redis.php';
|
|
|
+ if ($cache) {
|
|
|
+ if (!empty(self::$redis)) {
|
|
|
+ return self::$redis;
|
|
|
+ }
|
|
|
}
|
|
|
- $conf = require($dbcfg);
|
|
|
+ $conf = require(self::$configPath . 'redis.php');
|
|
|
$redis = new \Redis();
|
|
|
$ret = $redis->connect($conf['host'], $conf['port']);
|
|
|
if (!$ret) {
|