stanley-king 4 éve
szülő
commit
f296f13337

+ 1 - 1
core/framework/core/base.php

@@ -122,7 +122,7 @@ final class Base
 	 * run
 	 */
 	public static function run() {
-		performance_helper::clear();
+        perfor_clear();
         self::cp();
         self::init();
         self::control();

+ 1 - 1
helper/fcgi_server.php

@@ -74,7 +74,7 @@ class fcgi_server
 
             ob_start();
             $this->clear_global();
-            performance_helper::clear();
+            perfor_clear();
             http_header::instance()->start();
 
             try

+ 6 - 1
helper/fcgisrv/BaseServer.php

@@ -69,7 +69,9 @@ abstract class BaseServer
 
             ob_start();
             $this->clear_global();
-            performance_helper::clear();
+            perfor_clear();
+
+            perfor_start();
             Log::start_sql_log();
             init_request();
             init_cookie($_SERVER['HTTP_COOKIE']);
@@ -84,6 +86,9 @@ abstract class BaseServer
             Log::end_sql_log();
             $msg = sprintf("request time=%.6f\r\n\r\n",microtime(true) - $start);
             Log::record($msg ,Log::DEBUG);
+
+            $perlog = perfor_log();
+            Log::record("perlog = {$perlog}" ,Log::DEBUG);
         }
 
         fcgi_fini();

+ 17 - 5
helper/performance_helper.php

@@ -44,14 +44,17 @@ class performance_helper
         array_push($this->mMsgs,$msg);
     }
 
-    public static function clear() {
-        self::instance()->mMsgs = array();
+    public function clear()
+    {
+        $this->mMsgs = [];
     }
 
-    public static function format_log() {
-        foreach(self::instance()->mMsgs as $val) {
-            echo $val . "<br/><br/>";
+    public function format_log() {
+        $content = '';
+        foreach($this->mMsgs as $val) {
+            $content .= $val . "<br/><br/>";
         }
+        return $content;
     }
 }
 
@@ -60,6 +63,11 @@ function perfor_start()
     performance_helper::instance()->start();
 }
 
+function perfor_log()
+{
+    return performance_helper::instance()->format_log();
+}
+
 function perfor_end($tag,$info = '')
 {
     performance_helper::instance()->push($tag,$info);
@@ -68,4 +76,8 @@ function perfor_end($tag,$info = '')
 function perfor_period($tag,$start,$info = '')
 {
     performance_helper::instance()->push($tag,$info,$start);
+}
+function perfor_clear()
+{
+    performance_helper::instance()->clear();
 }

+ 2 - 2
mobile/control/control.php

@@ -290,7 +290,7 @@ class mobileControl
 
             echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
             echo "性能关键统计:<br/><br/>";
-            performance_helper::format_log();
+            echo perfor_log();
 
             $sqls = Log::sql_log();
             echo "sql count = " . count($sqls) . "<br/><br/>";
@@ -348,7 +348,7 @@ class mobileControl
             echo "<br/><br/>";
             echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
             echo "性能关键统计:<br/><br/>";
-            performance_helper::format_log();
+            echo perfor_log();
             $sqls = Log::sql_log();
             echo "sql count = " . count($sqls) . "<br/><br/>";
 

+ 2 - 2
mobile/control/merchantweb.php

@@ -65,7 +65,7 @@ class merchantwebControl
 
             echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
             echo "性能关键统计:<br/><br/>";
-            performance_helper::format_log();
+            echo perfor_log();
 
             $sqls = Log::sql_log();
             echo "sql count = " . count($sqls) . "<br/><br/>";
@@ -116,7 +116,7 @@ class merchantwebControl
             echo "<br/><br/>";
             echo sprintf("eclipse_time = %.6f <br/><br/>", self::eclipse_time());
             echo "性能关键统计:<br/><br/>";
-            performance_helper::format_log();
+            echo perfor_log();
             $sqls = Log::sql_log();
             echo "sql count = " . count($sqls) . "<br/><br/>";
 

+ 8 - 0
racc/control/refill.php

@@ -9,7 +9,9 @@ class refillControl extends merchantControl
 {
     public function __construct()
     {
+        perfor_end(__FUNCTION__,'start');
         parent::__construct();
+        perfor_end(__FUNCTION__,'end');
     }
 
     public function goodsOp()
@@ -57,6 +59,7 @@ class refillControl extends merchantControl
 
     public function addOp()
     {
+        perfor_end(__FUNCTION__,'start');
         [$success,$error] = $this->check_params($_GET);
         if($success === false) {
             return self::outerr(201,$error);
@@ -106,7 +109,12 @@ class refillControl extends merchantControl
                     'mch_order' => $mch_order,
                     'notify_url' => $notify_url ];
 
+        perfor_end(__FUNCTION__ . ' push queue start','start');
+
         queue\DispatcherClient::instance()->push('add',$params);
+
+        perfor_end(__FUNCTION__ . ' push queue end','start');
+
         return self::outsuccess(['state' => true]);
     }
 

+ 1 - 2
test/TestAccRefill.php

@@ -50,11 +50,10 @@ class TestAccRefill extends TestCase
     {
         $url = $this->mReqHost . "/racc/index.php";
 //        $url = 'https://www.baidu.com.cn';
-        for ($i = 0; $i < 1000; $i++)
+        for ($i = 0; $i < 10; $i++)
         {
             $params = $this->make_order();
             $resp = $this->send_md5($url, $params);
-            Log::record($resp, Log::DEBUG);
         }
     }
 

+ 2 - 2
test/TestRelationHelper.php

@@ -117,7 +117,7 @@ class testRelationHelper extends PHPUnit_Framework_TestCase
         }
         perfor_end("testSort","int sort");
 
-        performance_helper::instance()->format_log();
+        echo perfor_log();
     }
 
     public function testArrayInsert()
@@ -177,7 +177,7 @@ class testRelationHelper extends PHPUnit_Framework_TestCase
             //$relation->pass_subscribe();
         }
         perfor_end("testRelation","10000 pass_subscribe");
-        performance_helper::instance()->format_log();
+        echo perfor_log();
     }
 
     public function testInitInvitors()

+ 109 - 10
test/swool.php

@@ -8,25 +8,124 @@ require_once(BASE_CORE_PATH . '/lrlz.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
 
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+
+const LocalTest = 1;
+const NetTest = 2;
+
+const CurrentTest = NetTest;
+
 Co::set(['hook_flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_NATIVE_CURL ]);
 
+class acc
+{
+    private $mReqHost;
+    private $mKey;
+    private $mMchid;
+
+    public function __construct()
+    {
+        if (CurrentTest == LocalTest) {
+            $this->mReqHost = 'http://host.docker.internal';//BASE_SITE_URL;
+            $this->mMchid = 1;
+            $this->mKey = '1ff02223b771c0414468c8892151c602';
+        } else {
+            $this->mReqHost = 'http://121.89.212.167';
+            $this->mMchid = 1092;
+            $this->mKey = '210fe406954220f56085997d6a4c5b80';
+        }
+    }
+
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    public function testAddoil()
+    {
+        $url = $this->mReqHost . "/racc/index.php";
+        for ($i = 0; $i < 1000; $i++)
+        {
+            $params = $this->make_order();
+            $resp = $this->send_md5($url, $params);
+        }
+    }
+
+    private function make_order()
+    {
+        $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
+        $params = ['mchid' => $this->mMchid,
+            'cardno' => '13911129867',
+            'amount' => "30",
+            "act" => "refill",
+            "op" => "add",
+            'order_sn' => $this->make_sn(),
+            'notifyurl' => $notifyurl];
+
+        return $params;
+    }
+    private function send_md5($url, $params)
+    {
+        $body = $this->body($params);
+        $body .= "&key={$this->mKey}";
+        $params['sign'] = md5($body);
+
+        $resp = http_request($url, $params);
+        Log::record("resp:{$resp}", Log::DEBUG);
+
+        return $resp;
+    }
+    private function body($params)
+    {
+        ksort($params);
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+    private function checkEmpty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function make_sn()
+    {
+        return mt_rand(1000, 9999)
+            . sprintf('%010d', time())
+            . sprintf('%06d', (float)microtime() * 1000000);
+    }
+}
+
+
 go(function ()
 {
-    $n = 1000;
+    $n = 10;
     $i = 0;
     Log::record("start {$i}", Log::DEBUG);
 
+    $acc = new acc();
+
     while ($n--) {
-        go(function () use ($i) {
-            Log::record("start {$i}", Log::DEBUG);
-            $resp = http_request('https://www.xyzshops.cn/mobile/index.php?act=index&op=index&client_type=ios');
-            Log::record("recv {$i} size=" . strlen($resp), Log::DEBUG);
-            $resp = http_request('https://www.xyzshops.cn/mobile/index.php?act=index&op=index&client_type=ios');
-            Log::record("recv {$i} size=" . strlen($resp), Log::DEBUG);
-            $resp = http_request('https://www.xyzshops.cn/mobile/index.php?act=index&op=index&client_type=ios');
-            Log::record("recv {$i} size=" . strlen($resp), Log::DEBUG);
+        go(function () use ($i,$acc) {
+            $acc->testAddoil();
         });
         $i++;
-        Co::sleep(0.0001);
     }
 });