mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 02:37:58 +08:00
Add Memory Leak Detection Middleware to Swoole Tracker (#2747)
This commit is contained in:
parent
8f33ddbdf9
commit
7cf0d5894c
@ -233,14 +233,16 @@ php -r "trackerAnalyzeLeak();"
|
||||
|
||||
通过调用 `trackerCleanLeak()` 可以清除泄漏日志,重新开始。[了解更多内存检测工具使用细节](https://www.kancloud.cn/swoole-inc/ee-help-wiki/1941569)
|
||||
|
||||
在 Hyperf 中如果需要检测 HTTP Server 中的内存泄漏,可以在 `config/autoload/aspects.php` 配置以下 `Aspect`:
|
||||
如果需要在 Hyperf 中检测 HTTP Server 中的内存泄漏,可以在 `config/autoload/middlewares.php` 添加一个全局中间件:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
return [
|
||||
Hyperf\SwooleTracker\Aspect\OnRequestAspect::class,
|
||||
'http' => [
|
||||
Hyperf\SwooleTracker\Middleware\HookMallocMiddleware::class,
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
其他 Server 可以参照此 `Aspect` 进行重写使用。
|
||||
其他类型 Server 同理。
|
||||
|
@ -17,6 +17,9 @@ use Hyperf\HttpServer\Server;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use function trackerHookMalloc;
|
||||
|
||||
/**
|
||||
* @deprecated v2.1 use HookMallocMiddleware instead.
|
||||
*/
|
||||
class OnRequestAspect extends AbstractAspect
|
||||
{
|
||||
public $classes = [
|
||||
|
29
src/swoole-tracker/src/Middleware/HookMallocMiddleware.php
Normal file
29
src/swoole-tracker/src/Middleware/HookMallocMiddleware.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
namespace Hyperf\SwooleTracker\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use function trackerHookMalloc;
|
||||
|
||||
class HookMallocMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if (function_exists('trackerHookMalloc')) {
|
||||
trackerHookMalloc();
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user