@@ -89,6 +89,13 @@ class Manager
8989 */
9090 protected $ tracker ;
9191
92+ /**
93+ * 内存限制 0为关闭
94+ * @var int
95+ */
96+ protected $ taskMemoryLimit = 0 ;
97+ protected $ workerMemoryLimit = 0 ;
98+
9299 /**
93100 * Server events.
94101 *
@@ -323,14 +330,17 @@ public function onWorkerStart($server, $workerId)
323330 $ this ->container ->make ('events ' )->dispatch (Event::WORKER_START , func_get_args ());
324331 $ this ->clearCache ();
325332
333+ $ config = $ this ->container ->make ('config ' );
326334 // init laravel app in task workers
327335 if ($ server ->taskworker ) {
336+ $ this ->taskMemoryLimit = $ config ->get ('swoole_http.server.task_memory_limit ' );
337+
328338 $ this ->setProcessName ('task ' );
329339 $ this ->createTaskApplication ();
330340 $ this ->setLaravelApp ();
331341 $ this ->bindToLaravelApp ();
332342 } else {
333- $ config = $ this -> container -> make ( ' config ' );
343+ $ this -> workerMemoryLimit = $ config -> get ( ' swoole_http.server.worker_memory_limit ' );
334344 $ this ->handleStatic = $ config ->get ('swoole_http.handle_static_files ' , true );
335345 $ this ->publicPath = $ config ->get ('swoole_http.server.public_path ' , base_path ('public ' ));
336346 $ this ->enableAccessLog = $ config ->get ('swoole_http.server.enable_access_log ' , false );
@@ -762,11 +772,7 @@ protected function logError(Exception $e)
762772 */
763773 protected function memoryLeakCheck ()
764774 {
765- if (isTaskWorkerStatus ()) {
766- $ limit = $ this ->container ->make ('config ' )->get ('swoole_http.server.task_memory_limit ' );
767- } else {
768- $ limit = $ this ->container ->make ('config ' )->get ('swoole_http.server.worker_memory_limit ' );
769- }
775+ $ limit = isTaskWorkerStatus () ? $ this ->taskMemoryLimit : $ this ->workerMemoryLimit ;
770776 if ($ limit ) {
771777 $ memory = memory_get_usage (true );
772778 if ($ memory > $ limit ) {
0 commit comments