modify
This commit is contained in:
@@ -24,9 +24,9 @@ class Context extends BaseContext
|
|||||||
*/
|
*/
|
||||||
public static function setContext($id, $context, $key = null): mixed
|
public static function setContext($id, $context, $key = null): mixed
|
||||||
{
|
{
|
||||||
// if (!static::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
// return static::setStatic($id, $context, $key);
|
return static::setStatic($id, $context, $key);
|
||||||
// }
|
}
|
||||||
return self::setCoroutine($id, $context, $key);
|
return self::setCoroutine($id, $context, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,9 +106,9 @@ class Context extends BaseContext
|
|||||||
*/
|
*/
|
||||||
public static function getContext($id, $key = null): mixed
|
public static function getContext($id, $key = null): mixed
|
||||||
{
|
{
|
||||||
// if (!static::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
// return static::loadByStatic($id, $key);
|
return static::loadByStatic($id, $key);
|
||||||
// }
|
}
|
||||||
return static::loadByContext($id, $key);
|
return static::loadByContext($id, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ class Context extends BaseContext
|
|||||||
*/
|
*/
|
||||||
public static function getAllContext(): mixed
|
public static function getAllContext(): mixed
|
||||||
{
|
{
|
||||||
if (static::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return Coroutine::getContext() ?? [];
|
return Coroutine::getContext() ?? [];
|
||||||
} else {
|
} else {
|
||||||
return static::$_contents ?? [];
|
return static::$_contents ?? [];
|
||||||
@@ -170,7 +170,7 @@ class Context extends BaseContext
|
|||||||
if (!static::hasContext($id, $key)) {
|
if (!static::hasContext($id, $key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!static::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
if (!empty($key)) {
|
if (!empty($key)) {
|
||||||
unset(static::$_contents[$id][$key]);
|
unset(static::$_contents[$id][$key]);
|
||||||
} else {
|
} else {
|
||||||
@@ -192,7 +192,7 @@ class Context extends BaseContext
|
|||||||
*/
|
*/
|
||||||
public static function hasContext($id, $key = null): bool
|
public static function hasContext($id, $key = null): bool
|
||||||
{
|
{
|
||||||
if (!static::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return static::searchByStatic($id, $key);
|
return static::searchByStatic($id, $key);
|
||||||
}
|
}
|
||||||
return static::searchByCoroutine($id, $key);
|
return static::searchByCoroutine($id, $key);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use Exception;
|
|||||||
use HttpServer\Http\Context;
|
use HttpServer\Http\Context;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Snowflake\Exception\ConfigException;
|
use Snowflake\Exception\ConfigException;
|
||||||
|
use Swoole\Coroutine;
|
||||||
use Swoole\Coroutine\Channel;
|
use Swoole\Coroutine\Channel;
|
||||||
use Swoole\Timer;
|
use Swoole\Timer;
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ abstract class Pool extends Component
|
|||||||
if (isset($this->_items[$name]) && $this->_items[$name] instanceof Channel) {
|
if (isset($this->_items[$name]) && $this->_items[$name] instanceof Channel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Context::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->_items[$name] = new Channel((int)$max);
|
$this->_items[$name] = new Channel((int)$max);
|
||||||
@@ -165,7 +166,7 @@ abstract class Pool extends Component
|
|||||||
*/
|
*/
|
||||||
protected function getFromChannel($name, mixed $callback): mixed
|
protected function getFromChannel($name, mixed $callback): mixed
|
||||||
{
|
{
|
||||||
if (!Context::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return $this->createClient($name, $callback);
|
return $this->createClient($name, $callback);
|
||||||
}
|
}
|
||||||
if (!isset($this->_items[$name])) {
|
if (!isset($this->_items[$name])) {
|
||||||
@@ -272,7 +273,7 @@ abstract class Pool extends Component
|
|||||||
*/
|
*/
|
||||||
public function size(string $name): mixed
|
public function size(string $name): mixed
|
||||||
{
|
{
|
||||||
if (!Context::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!isset($this->_items[$name])) {
|
if (!isset($this->_items[$name])) {
|
||||||
@@ -288,7 +289,7 @@ abstract class Pool extends Component
|
|||||||
*/
|
*/
|
||||||
public function push(string $name, mixed $client)
|
public function push(string $name, mixed $client)
|
||||||
{
|
{
|
||||||
if (!Context::inCoroutine()) {
|
if (Coroutine::getCid() === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isset($this->_items[$name])) {
|
if (!isset($this->_items[$name])) {
|
||||||
@@ -307,7 +308,7 @@ abstract class Pool extends Component
|
|||||||
*/
|
*/
|
||||||
public function clean(string $name)
|
public function clean(string $name)
|
||||||
{
|
{
|
||||||
if (!Context::inCoroutine() || !isset($this->_items[$name])) {
|
if (Coroutine::getCid() === -1 || !isset($this->_items[$name])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$channel = $this->_items[$name];
|
$channel = $this->_items[$name];
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class Logger extends Component
|
|||||||
$files = glob(storage(null, $dirName) . '/*');
|
$files = glob(storage(null, $dirName) . '/*');
|
||||||
if (count($files) >= 15) {
|
if (count($files) >= 15) {
|
||||||
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
|
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
|
||||||
if (Context::inCoroutine()) {
|
if (Coroutine::getCid() !== -1) {
|
||||||
Coroutine\System::exec($command);
|
Coroutine\System::exec($command);
|
||||||
} else {
|
} else {
|
||||||
\shell_exec($command);
|
\shell_exec($command);
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ class Redis extends Pool
|
|||||||
{
|
{
|
||||||
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
|
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
|
||||||
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
|
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
|
||||||
if (($redis = Context::getContext($coroutineName)) instanceof \Redis) {
|
if (!Context::hasContext($coroutineName)) {
|
||||||
return $redis;
|
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
|
||||||
}
|
}
|
||||||
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
|
return Context::getContext($coroutineName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user