浏览代码

add coroutine

stanley-king 4 年之前
父节点
当前提交
be6cd4fea4

+ 18 - 20
core/framework/core/base.php

@@ -227,29 +227,27 @@ final class Base
 		session_start();
 	}
 
-	public static function autoload($class)
-	{
-		$class = strtolower($class);
-		if (ucwords(substr($class,-5)) == 'Class' ){
-			if (!@include_once(BASE_PATH.'/framework/libraries/'.substr($class,0,-5).'.class.php')){
-				exit("Class Error: {$class}.isn't exists!");
-			}
-		}elseif (ucwords(substr($class,0,5)) == 'Cache' && $class != 'cache'){
-			if (!@include_once(BASE_CORE_PATH.'/framework/cache/'.substr($class,0,5).'.'.substr($class,5).'.php')){
-				exit("Class Error: {$class}.isn't exists!");
-			}
-		}elseif ($class == 'db'){
-			if (!@include_once(BASE_CORE_PATH.'/framework/db/'.strtolower(DBDRIVER).'.php')){
-				exit("Class Error: {$class}.isn't exists!");
-			}
-		}
-		elseif(substr($class,0,9) == 'phpexcel_') {
+    public static function autoload($class)
+    {
+        $class = strtolower($class);
+        if (ucwords(substr($class, -5)) == 'Class') {
+            if (!@include_once(BASE_PATH . '/framework/libraries/' . substr($class, 0, -5) . '.class.php')) {
+                exit("Class Error: {$class}.isn't exists!");
+            }
+        } elseif (ucwords(substr($class, 0, 5)) == 'Cache' && $class != 'cache') {
+            if (!@include_once(BASE_CORE_PATH . '/framework/cache/' . substr($class, 0, 5) . '.' . substr($class, 5) . '.php')) {
+                exit("Class Error: {$class}.isn't exists!");
+            }
+        } elseif ($class == 'db') {
+            if (!@include_once(BASE_CORE_PATH . '/framework/db/' . strtolower(DBDRIVER) . '.php')) {
+                exit("Class Error: {$class}.isn't exists!");
+            }
+        } elseif (substr($class, 0, 9) == 'phpexcel_') {
 
-        }
-		elseif (!@include_once(BASE_CORE_PATH.'/framework/libraries/'.$class.'.php')){
+        } elseif (!@include_once(BASE_CORE_PATH . '/framework/libraries/' . $class . '.php')) {
             exit("Class Error: {$class}.isn't exists!");
         }
-	}
+    }
 
 	public static function mobile_autoload($class)
 	{

+ 0 - 1
core/framework/db/mysql.php

@@ -102,7 +102,6 @@ class Db
 
 	public static function ping($host = 'master') {
 	    if (is_object(self::$link[$host])) {
-// 	    if (is_object(self::$link[$host]) && !mysql_ping(self::$link[$host])) {
 	        mysql_close(self::$link[$host]);
 	        self::$link[$host] = null;
 	    }

+ 11 - 1
core/framework/libraries/log.php

@@ -122,7 +122,17 @@ class Log
     private static function write($message, $level)
     {
         $now = @date('Y-m-d H:i:s', time());
-        $pid = posix_getpid();
+
+        define('USE_COROUTINE',true);
+
+
+        if(defined('USE_COROUTINE') && USE_COROUTINE === true) {
+            $pid = Swoole\Coroutine::getCid();
+        }
+        else {
+            $pid = posix_getpid();
+        }
+
 
         $appid = empty(APP_ID) ? '' : APP_ID;
 

+ 3 - 3
core/framework/libraries/model.php

@@ -781,13 +781,13 @@ class ModelDb
             $sql = $this->buildSelectSql($options);
             if ($options['cache'] === true)
             {
-                $key =  is_string($_cache['cache_key']) ? $_cache['cache_key'] : md5($sql);
+                $key = is_string($_cache['cache_key']) ? $_cache['cache_key'] : md5($sql);
                 if (isset($_cache[$key])) {
                     return $_cache[$key];
                 }
             }
-            $result = DB::getAll($sql,($options['lock'] === true || $options['master'] === true || defined('TRANS_MASTER')) ? 'master' : 'slave');
-            if ($options['cache'] === true && !isset($_cache[$key])){
+            $result = DB::getAll($sql, ($options['lock'] === true || $options['master'] === true || defined('TRANS_MASTER')) ? 'master' : 'slave');
+            if ($options['cache'] === true && !isset($_cache[$key])) {
                 $_cache[$key] = $result;
             }
             return $result;

+ 3 - 6
data/config/dev/refill.ini.php

@@ -19,7 +19,7 @@ $config['refill_specs'] = [
 $oil_providers = [];
 $config['oil_providers'] = $oil_providers;
 
-$baidu_phone = ['name' => 'baizeyd', 'store_id' => 8,
+$baidu_phone = ['name' => 'baidu', 'store_id' => 8,
     'amount' => [
         10 => [['goods_id' => 6245, 'price' => 9.51, 'quality' => 1, 'card_type' => 'chinaunicom,chinatelecom'],
                ['goods_id' => 6245, 'price' => 9.61, 'quality' => 1, 'card_type' => 'chinamobile'],
@@ -32,8 +32,5 @@ $baidu_phone = ['name' => 'baizeyd', 'store_id' => 8,
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 $phone_providers = [
-    ['name' => 'baizeyd', 'cfg' => $baidu_phone, 'opened' => true, 'sort' => 1]];
-$config['phone_providers'] = $phone_providers;
-
-$config['refill_oil_specs'] = [100 , 200 , 500 , 1000 , 2000];
-$config['refill_phone_specs'] = [10 , 20 , 30 , 50 , 100 , 200 , 300 , 500];
+    ['name' => 'baidu', 'cfg' => $baidu_phone, 'opened' => true, 'sort' => 1]];
+$config['phone_providers'] = $phone_providers;

+ 0 - 1
helper/refill/api/test/baidu/RefillPhone.php

@@ -5,7 +5,6 @@ namespace refill\baidu;
 require_once(BASE_HELPER_RAPI_PATH . '/baidu/config.php');
 
 use refill;
-use Log;
 use mtopcard;
 
 class RefillPhone extends refill\IRefillPhone

+ 4 - 1
rdispatcher/codispatcher.php

@@ -3,8 +3,10 @@ declare(strict_types=0);
 
 define('APP_ID', 'rdispatcher');
 define('MOBILE_SERVER',true);
+define('USE_COROUTINE',true);
 define('SUPPORT_PTHREAD',false);
 
+
 define('BASE_ROOT_PATH',str_replace('/rdispatcher','',dirname(__FILE__)));
 define('BASE_PATH',BASE_ROOT_PATH . '/rdispatcher');
 
@@ -37,7 +39,8 @@ require_once(BASE_PATH . '/proxy.php');
 //Co::set(['hook_flags' => SWOOLE_HOOK_ALL]);
 
 //目前没发现问题
-Co::set(['hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP]);
+//Co::set(['hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP]);
+Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL]);
 
 if (empty($_SERVER['argv'][1])) exit('parameter error');
 $count = intval($_SERVER['argv'][1]);