国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

在webman中使用swoole一鍵協(xié)程化不生效

193796273@qq.com

問題描述

在webman中使用swoole一鍵協(xié)程化不生效

程序代碼

//webman server.php 配置
return [
    'listen'           => 'http://0.0.0.0:8787',
    'transport'        => 'tcp',
    'context'          => [],
    'name'             => 'webman',
    'count'            => cpu_count() * 10,
    'user'             => '',
    'group'            => '',
    'reusePort'        => false,
    'event_loop'       => Workerman\Events\Swoole::class,
    'stop_timeout'     => 2,
    'pid_file'         => runtime_path() . '/webman.pid',
    'status_file'      => runtime_path() . '/webman.status',
    'stdout_file'      => runtime_path() . '/logs/stdout.log',
    'log_file'         => runtime_path() . '/logs/workerman.log',
    'max_package_size' => 10 * 1024 * 1024
];

// 測(cè)試一鍵協(xié)程化
\Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
go(function () {
    Db::select("select CONNECTION_ID(),SLEEP(30);");
});

報(bào)錯(cuò)信息

mysql:
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. (SQL: select CONNECTION_ID(),SLEEP(30);)

redis:
Uncaught Swoole\Error:
Socket#12 has already been bound to another coroutine#25, reading of the same socket in coroutine#29 at t
he same time is not allowed in

操作系統(tǒng)及workerman/webman等框架組件具體版本

webman版本1.4.7
swoole版本5.0.2
php版本8.1
操作系統(tǒng):centos7

2347 2 0
2個(gè)回答

胡桃

用 Channel 實(shí)現(xiàn)連接池。
參考:https://gitee.com/mix-php/mix/tree/master/src/object-pool

有人問過這種問題:http://wtbis.cn/q/10007

  • 193796273@qq.com 2023-03-31

    感謝你的回答!不過使用連接池并不是我想要達(dá)到的目的

法師
Socket#12 has already been bound to another coroutine#25, reading of the same socket in coroutine#29

這個(gè)報(bào)錯(cuò)說(shuō)明一鍵協(xié)程已經(jīng)生效了。
報(bào)錯(cuò)的意思是數(shù)據(jù)庫(kù)連接不能同時(shí)被多個(gè)協(xié)程使用,要么每個(gè)協(xié)程一個(gè)數(shù)據(jù)庫(kù)連接,要么使用連接池機(jī)制。
協(xié)程不是所有composer庫(kù)都支持,你要用協(xié)程就必須改造所有的第三方composer庫(kù),保證這些庫(kù)互斥使用某些資源,保證不會(huì)全局變量污染等等。

  • 193796273@qq.com 2023-03-31

    感謝你的回答!按swoole官網(wǎng)的文檔,一鍵協(xié)程化【https://wiki.swoole.com/#/runtime】 說(shuō)明,我以為可以不需要使用相關(guān)連接池。。。

  • 193796273@qq.com 2023-03-31

    如果是如你所說(shuō)的話,那我就必須要用連接池了,不然每個(gè)協(xié)程內(nèi)都實(shí)例化一個(gè)新的連接出來(lái),那連接數(shù)很快就會(huì)打滿

年代過于久遠(yuǎn),無(wú)法發(fā)表回答
??