This commit is contained in:
as2252258@163.com
2021-05-04 03:07:11 +08:00
parent 6230db7a4f
commit a8eebeb902
4 changed files with 19 additions and 18 deletions
+6 -5
View File
@@ -8,6 +8,7 @@ use Exception;
use HttpServer\Http\Context;
use JetBrains\PhpStorm\Pure;
use Snowflake\Exception\ConfigException;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
use Swoole\Timer;
@@ -149,7 +150,7 @@ abstract class Pool extends Component
if (isset($this->_items[$name]) && $this->_items[$name] instanceof Channel) {
return;
}
if (!Context::inCoroutine()) {
if (Coroutine::getCid() === -1) {
return;
}
$this->_items[$name] = new Channel((int)$max);
@@ -165,7 +166,7 @@ abstract class Pool extends Component
*/
protected function getFromChannel($name, mixed $callback): mixed
{
if (!Context::inCoroutine()) {
if (Coroutine::getCid() === -1) {
return $this->createClient($name, $callback);
}
if (!isset($this->_items[$name])) {
@@ -272,7 +273,7 @@ abstract class Pool extends Component
*/
public function size(string $name): mixed
{
if (!Context::inCoroutine()) {
if (Coroutine::getCid() === -1) {
return 0;
}
if (!isset($this->_items[$name])) {
@@ -288,7 +289,7 @@ abstract class Pool extends Component
*/
public function push(string $name, mixed $client)
{
if (!Context::inCoroutine()) {
if (Coroutine::getCid() === -1) {
return;
}
if (!isset($this->_items[$name])) {
@@ -307,7 +308,7 @@ abstract class Pool extends Component
*/
public function clean(string $name)
{
if (!Context::inCoroutine() || !isset($this->_items[$name])) {
if (Coroutine::getCid() === -1 || !isset($this->_items[$name])) {
return;
}
$channel = $this->_items[$name];
+1 -1
View File
@@ -179,7 +179,7 @@ class Logger extends Component
$files = glob(storage(null, $dirName) . '/*');
if (count($files) >= 15) {
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
if (Context::inCoroutine()) {
if (Coroutine::getCid() !== -1) {
Coroutine\System::exec($command);
} else {
\shell_exec($command);
+3 -3
View File
@@ -53,10 +53,10 @@ class Redis extends Pool
{
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
if (($redis = Context::getContext($coroutineName)) instanceof \Redis) {
return $redis;
if (!Context::hasContext($coroutineName)) {
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
}
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
return Context::getContext($coroutineName);
}