swoole-foundation / yii2-swoole-extension

running yii2 app on swoole
MIT License
41 stars 5 forks source link

开启协程的思路 #7

Closed qqqqbbbb closed 2 years ago

qqqqbbbb commented 2 years ago

您好,请问启用协程的思路是怎样的呢

xialeistudio commented 2 years ago

需要处理好全局变量

  1. 成本低方案,构造全局Map,key为协程ID,value为全局变量

    $globalContainer = [
    '1' => [
    'db' => 'xxx',
    'user' => 'xxx' 
    ]
    ];
  2. 成本高方案,全局变量只作为,每个协程单独从池中获取资源,该资源协程间不共享