From 7be00a7bba0cfbe1f8edf0f51cd1ff7135fe89f3 Mon Sep 17 00:00:00 2001 From: bingcool <2437667702@qq.com> Date: Tue, 8 Aug 2023 00:02:57 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E4=BF=AE=E5=A4=8D=E5=8D=8F=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0fetch=E5=AF=B9=E8=B1=A1=E4=B8=8D=E5=90=8C=E5=8D=8F?= =?UTF-8?q?=E7=A8=8B=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/Controller/IndexController.php | 2 +- Test/Scripts/FixedUser.php | 2 +- src/Core/Coroutine/CoroutineManager.php | 13 +++++-------- src/Core/Coroutine/PoolsHandler.php | 10 +++++----- src/Core/Coroutine/Timer.php | 6 +++--- src/Core/Dto/ContainerObjectDto.php | 21 +++++++++++++++++++++ 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Test/Controller/IndexController.php b/Test/Controller/IndexController.php index 44417dfa..5c2352ff 100644 --- a/Test/Controller/IndexController.php +++ b/Test/Controller/IndexController.php @@ -188,7 +188,7 @@ public function testTransactionAddOrder() ]); $db->commit(); - + var_dump('commit'); }catch (\Throwable $e) { $db->rollback(); var_dump($e->getMessage()); diff --git a/Test/Scripts/FixedUser.php b/Test/Scripts/FixedUser.php index a8f4b0d3..afb97001 100644 --- a/Test/Scripts/FixedUser.php +++ b/Test/Scripts/FixedUser.php @@ -35,7 +35,7 @@ public function fixName() try { var_dump('CID11='.\Swoole\Coroutine::getCid()); var_dump('spl_object_id-11='.spl_object_id($this->db)); - $result1 = Application::getApp()->get('db')->newQuery()->table('tbl_users')->limit(1)->select()->toArray(); + $result1 = $this->db->newQuery()->table('tbl_users')->limit(1)->select()->toArray(); var_dump($result1); }catch (\Throwable $exception) { var_dump($exception->getMessage()); diff --git a/src/Core/Coroutine/CoroutineManager.php b/src/Core/Coroutine/CoroutineManager.php index 8ef40902..3b2f0f0c 100644 --- a/src/Core/Coroutine/CoroutineManager.php +++ b/src/Core/Coroutine/CoroutineManager.php @@ -66,15 +66,12 @@ public function getCoroutineStatus(): array */ public function listCoroutines(): array { - if (method_exists('Swoole\\Coroutine', 'list')) { - $cids = []; - $coros = \Swoole\Coroutine::list(); - foreach ($coros as $cid) { - array_push($cids, $cid); - } - return $cids; + $cids = []; + $coros = \Swoole\Coroutine::list(); + foreach ($coros as $cid) { + array_push($cids, $cid); } - return []; + return $cids; } /** diff --git a/src/Core/Coroutine/PoolsHandler.php b/src/Core/Coroutine/PoolsHandler.php index 22264a37..78511804 100644 --- a/src/Core/Coroutine/PoolsHandler.php +++ b/src/Core/Coroutine/PoolsHandler.php @@ -183,7 +183,7 @@ public function pushObj($obj) { \Swoole\Coroutine::create(function () use ($obj) { $isPush = true; - if (isset($obj->__objExpireTime) && time() > $obj->__objExpireTime) { + if (!is_null($obj->__objExpireTime) && time() > $obj->__objExpireTime) { $isPush = false; } @@ -267,11 +267,13 @@ protected function make(int $num = 1) $containerObject = $this->buildContainerObject($obj, $this->poolName); $this->channel->push($containerObject, $this->pushTimeout); + unset($obj); } } /** * @param object $object + * @param string $poolName * @return ContainerObjectDto */ private function buildContainerObject(object $object, string $poolName) @@ -291,15 +293,13 @@ private function buildContainerObject(object $object, string $poolName) protected function pop() { $containerObject = $this->channel->pop($this->popTimeout); - - if (is_object($containerObject) && isset($containerObject->__objExpireTime) && time() > $containerObject->__objExpireTime) { + if (is_object($containerObject) && !is_null($containerObject->__objExpireTime) && time() > $containerObject->__objExpireTime) { //rebuild object unset($containerObject); $this->make(1); + $containerObject = $this->channel->pop($this->popTimeout); } - $containerObject = $this->channel->pop($this->popTimeout); - return is_object($containerObject) ? $containerObject : null; } } \ No newline at end of file diff --git a/src/Core/Coroutine/Timer.php b/src/Core/Coroutine/Timer.php index fbfa63a7..da3c36c6 100644 --- a/src/Core/Coroutine/Timer.php +++ b/src/Core/Coroutine/Timer.php @@ -48,12 +48,12 @@ public static function tick(int $timeMs, callable $callable) /** * cancel tick timer * - * @param Channel $channel + * @param Channel $timeChannel * @return bool */ - public static function cancel(Channel $channel): bool + public static function cancel(Channel $timeChannel): bool { - return $channel->push(1); + return $timeChannel->push(1); } /** diff --git a/src/Core/Dto/ContainerObjectDto.php b/src/Core/Dto/ContainerObjectDto.php index 45e82230..6ee84caf 100644 --- a/src/Core/Dto/ContainerObjectDto.php +++ b/src/Core/Dto/ContainerObjectDto.php @@ -11,6 +11,7 @@ namespace Swoolefy\Core\Dto; +use Swoolefy\Core\Swfy; use Swoolefy\Core\Application; class ContainerObjectDto extends AbstractDto @@ -87,6 +88,26 @@ public function getObject() */ public function __call($name, $arguments) { + $cid = \Swoole\Coroutine::getCid(); + $appConf = Swfy::getAppConf(); + if (!empty($appConf['enable_component_pools']) && is_array($appConf['enable_component_pools'])) { + if (Swfy::isWorkerProcess()) { + if (!isset($appConf['enable_component_pools'][$this->__comAliasName])) { + if ($cid != $this->__coroutineId) { + return Application::getApp()->get($this->__comAliasName)->$name(...$arguments); + } + } + }else { + if ($cid != $this->__coroutineId) { + return Application::getApp()->get($this->__comAliasName)->$name(...$arguments); + } + } + }else { + if ($cid != $this->__coroutineId) { + return Application::getApp()->get($this->__comAliasName)->$name(...$arguments); + } + } + return $this->__object->$name(...$arguments); }