swoole-inc / report

关于 Swoole 文档中的内容问题(如错别字、示例错误、内容缺失等)以及需求建议
https://wiki.swoole.com
7 stars 2 forks source link

run和go #55

Open 449134904 opened 2 years ago

449134904 commented 2 years ago

From wiki page: https://wiki.swoole.com/#/runtime?id=swoole_hook_tcp


Co\run() 是创建了协程容器,go() 是创建协程

$s = microtime(true); run(function () { for($c = 10; $c--;) { print_r($c); echo "\n"; go(function () { print_r(date("Y-m-d H:i:s")); echo "\n"; $swoole_mysql = new MySQL(); $swoole_mysql->connect([ 'host' => '127.0.0.1', 'port' => 3306, 'user' => 'root', 'password' => '123123', 'database' => 'blt_test', ]); $sta = $swoole_mysql->prepare('select * from oscshop_lionfish_comshop_coupon_list limit 1000');

        for($n = 100; $n--;) {

// $res = $swoole_mysql->query('select * from oscshop_lionfish_comshop_coupon_list'); // var_dump($res); $res = $sta->execute(); // assert(count($res)>0); if(!assert(count($res) > 0)) { var_dump($res); } // var_dump(assert(count($res)>0)); } }); } }); //Event::wait(); echo '耗时:'.(microtime(true) - $s)."s\n";

我发现去除run耗时更少,请问这有什么区别吗?