[Swoole Tracker](https://business.swoole.com/tracker/index) is a set of enterprise-level tools officially powered by Swoole, including PHP and Swoole analysis, debugging tools, and application performance management (APM) platform. The Swoole Tracker focus on conventional FPM and Swoole resident process business, provide comprehensive performance monitoring, analysis and debugging solutions. (former name: Swoole Enterprise)
Swoole Tracker can help companies automatically analyze and summarize important system calls and locate specific PHP business codes, intelligently and accurately. It optimize business application performance, and provides a powerful debugging tool chain to escort corporate business and improve IT production efficiency.
- Keep abreast of the application architecture model
> Automatically discover the topological structure of applications and display it. Keep abreast of application architecture models.
- Distributed cross-application link tracking
> Support non-intrusive distributed cross-application link tracking, making each request clear at a glance. Fully supporting coroutine/non-coroutine environment. Support real-time data visualization.
- Comprehensive analysis and reporting of service status
> Invocation information reported by the service in various dimensions, such as total flow, average time consumption, timeout rate, etc., and comprehensively analyze and report the service status.
- Powerful debugging toolchain
> The system supports remote debugging, which can be remotely opened in the background of the system to perform memory leaks detection, block detection, code performance analysis, and check the call stack. It also supports manual debugging and viewing results in the background.
- Support FPM and Swoole
> Perfect support for PHP-FPM environment, not limited to use in Swoole.
- Complete system monitoring
> Support complete system monitoring, zero-cost deployment, monitor the CPU, memory, network, disk and other resources, which can be easily integrated into the existing alarm system.
- Install with one simple click and zero-cost access
> Avoid and reduce the overall investment risk. The client of this system provides scripts that can be deployed with one click, and the server can run in the Docker environment, which is convenient.
- Improve production efficiency of various departments
> Track service and code-level performance bottlenecks in complex systems, help development departments improve work efficiency, and focus on core business work.
After registering an account, enter the [console](https://business.swoole.com/SwooleTracker/catdemo) to apply for a trial and download the corresponding installation script.
The `v2.5.0` and above versions of `Swoole Tracker` support automatically generating application names and creating applications without modifying any code.
After the installation, register the `Hyperf\SwooleTracker\Middleware\HttpServerMiddleware` middleware in the `config/autoload/middlewares.php` configuration file, as follows:
If you use the `jsonrpc-http` protocol to implement the `RPC` service, you also need to configure the following `Aspect` in `config/autoload/aspects.php`:
Swoole Tracker is a commercial product that has the ability to detect memory leaks. However, Swoole Tracker provides the function of memory leak detection to the PHP community for free to improve the PHP ecosystem and show thanks and respect to the community. The following will outline its usage.
1. Go to [Swoole Tracker Web](https://business.swoole.com/SwooleTracker/download/) to download the latest Swoole Tracker extension;
2. Same as what mentioned above to add the extension, and add another line of configuration:
```ini
;enable leak detection
apm.enable_malloc_hook=1
```
!> Note: Do not enable it when composer installs dependencies. Do not enable it when generating proxy class cache.
1. According to your own business, add a call of `trackerHookMalloc()` at the beginning of Swoole `onReceive` or `onRequest` event:
```php
$http->on('request', function ($request, $response) {
After each call ends (the first call will not be recorded), a leaked message will be generated in the `/tmp/trackerleak` log. We can use the `trackerAnalyzeLeak()` function on the CLI command line to analyze the leak log to generate a report.
```shell
php -r "trackerAnalyzeLeak();"
```
Report form will be like the following:
when there is no leak:
```
[16916 (Loop 5)] ✅ Nice!! No Leak Were Detected In This Loop
```
where `16916` represents process id, and `Loop 5` means the leak message in the 5th time main function calling.
It means that lines 125 and 129 of `http_server.php` respectively leaked 12928 bytes of memory (in total 25216 bytes) in the 8th time calling.
You can clear the leak log by calling `trackerCleanLeak()`. [For more details about the memory detection tools](https://www.kancloud.cn/swoole-inc/ee-help-wiki/1941569)
If you need to detect memory leaks in HTTP Server in Hyperf, you can add a global middleware in `config/autoload/middlewares.php`: