diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index bc65ad3ea..d2816e430 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -17,6 +17,7 @@ - [#2951](https://github.com/hyperf/hyperf/pull/2951) Optimized code for model-cache, which will delete model cache only once, when using it in transaction. - [#2953](https://github.com/hyperf/hyperf/pull/2953) Hide `Swoole\ExitException` trace message in command. +- [#2963](https://github.com/hyperf/hyperf/pull/2963) Removed `onStart` event from server default callbacks when the mode is `SWOOLE_BASE`. # v2.0.22 - 2020-12-07 diff --git a/src/server/src/Server.php b/src/server/src/Server.php index e6f7561d7..43941ef06 100644 --- a/src/server/src/Server.php +++ b/src/server/src/Server.php @@ -209,18 +209,24 @@ class Server implements ServerInterface protected function defaultCallbacks() { - $hasCallback = class_exists(Bootstrap\StartCallback::class) && - class_exists(Bootstrap\ManagerStartCallback::class) && - class_exists(Bootstrap\WorkerStartCallback::class); + $hasCallback = class_exists(Bootstrap\StartCallback::class) + && class_exists(Bootstrap\ManagerStartCallback::class) + && class_exists(Bootstrap\WorkerStartCallback::class); if ($hasCallback) { - return [ - SwooleEvent::ON_START => [Bootstrap\StartCallback::class, 'onStart'], + $callbacks = [ SwooleEvent::ON_MANAGER_START => [Bootstrap\ManagerStartCallback::class, 'onManagerStart'], SwooleEvent::ON_WORKER_START => [Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], SwooleEvent::ON_WORKER_STOP => [Bootstrap\WorkerStopCallback::class, 'onWorkerStop'], SwooleEvent::ON_WORKER_EXIT => [Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], ]; + if ($this->server->mode === SWOOLE_BASE) { + return $callbacks; + } + + return array_merge([ + SwooleEvent::ON_START => [Bootstrap\StartCallback::class, 'onStart'], + ], $callbacks); } return [