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

在webman中使用swoole一鍵協程化不生效

193796273@qq.com

問題描述

在webman中使用swoole一鍵協程化不生效

程序代碼

//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
];

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

報錯信息

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

2468 2 0
2個回答

胡桃

用 Channel 實現連接池。
參考:https://gitee.com/mix-php/mix/tree/master/src/object-pool

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

  • 193796273@qq.com 2023-03-31

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

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

這個報錯說明一鍵協程已經生效了。
報錯的意思是數據庫連接不能同時被多個協程使用,要么每個協程一個數據庫連接,要么使用連接池機制。
協程不是所有composer庫都支持,你要用協程就必須改造所有的第三方composer庫,保證這些庫互斥使用某些資源,保證不會全局變量污染等等。

  • 193796273@qq.com 2023-03-31

    感謝你的回答!按swoole官網的文檔,一鍵協程化【https://wiki.swoole.com/#/runtime】 說明,我以為可以不需要使用相關連接池。。。

  • 193796273@qq.com 2023-03-31

    如果是如你所說的話,那我就必須要用連接池了,不然每個協程內都實例化一個新的連接出來,那連接數很快就會打滿

年代過于久遠,無法發(fā)表回答
??