关于协程mysql的一段代码问题
来源:6-7 Swoole 协程精讲-基于2.x(下)
慕瓜3628079
2018-09-07
***<?php
$http = new swoole_http_server(“10.0.70.24”, 9501);
http−>on(′request′,function(http->on('request', function (http−>on(′request′,function(request, $response) {
echo time();
$swoole_mysql = new SwooleCoroutineMySQL();
$swoole_mysql->connect([
‘host’ => ‘127.0.0.1’,
‘port’ => 3306,
‘user’ => ‘root’,
‘password’ => ‘root’,
‘database’ => ‘ydstest’,
]);
$swoole_mysql2 = new SwooleCoroutineMySQL();
$swoole_mysql2->connect([
‘host’ => ‘127.0.0.1’,
‘port’ => 3306,
‘user’ => ‘root’,
‘password’ => ‘root’,
‘database’ => ‘ydstest’,
]);
$res = $swoole_mysql->query('select sleep(5),id from test_user ',10);
$rs = $swoole_mysql2->query(‘select sleep(10) from test_user where id=1’,15);
$response->header(‘Content-Type’,‘text/plain’);
response−>end(jsonencode(response->end(json_encode(response−>end(jsonencode(rs));
echo time();
});
$http->start();
为什么 这段代码执行时间是 15秒 不是预料的10秒呢
2回答
-
慕瓜3628079
提问者
2018-09-10
老师您好,我的swoole扩展版本是 swoole 4.1.1的
00 -
singwa
2018-09-09
您好。您的swoole是哪个版本的?
022018-09-18
相似问题