scoutapp / scout-apm-php
Scout 应用性能监控代理 - https://scoutapm.com
Requires
- php: 7.2.*|7.3.*|7.4.*|8.0.*|8.1.*|8.2.*|8.3.*
- ext-json: *
- ext-openssl: *
- ext-sockets: *
- ext-zlib: *
- php-http/discovery: ^1.14
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0|^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^1.0|^2.0|^3.0
- psr/simple-cache: ^1.0|^2.0|^3.0
- ralouphie/getallheaders: ^2.0.5|^3.0
- ramsey/uuid: ^3.0|^4.2.2
- webmozart/assert: ^1.0
Requires (Dev)
- composer-plugin-api: ^2.0
- api-ecosystem-for-laravel/dingo-api: ^3.0|^4.0
- doctrine/coding-standard: ^12.0
- guzzlehttp/guzzle: ^7.4
- laravel/framework: ^5.5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- laravel/lumen-framework: ^5.5.0|^6.0|^7.0|^8.0|^9.0|^10.0
- monolog/monolog: ^1.27|^2.5|^3.0
- nesbot/carbon: ^2.62.1 || ^3.5
- nyholm/psr7: ^1.5
- phpunit/phpunit: ^8.5.22|^9.5.2
- psalm/plugin-phpunit: ^0.16.1 || ^0.17 || ^0.18 || ^0.19
- symfony/config: ^4.0 || ^5.0 || ^6.0
- symfony/dependency-injection: ^4.0 || ^5.0 || ^6.0
- symfony/event-dispatcher: ^4.0 || ^5.0 || ^6.0
- symfony/http-kernel: ^4.0 || ^5.0 || ^6.0
- symfony/orm-pack: ^2.0
- symfony/process: ^3.0 || ^4.0 || ^5.0 || ^6.0
- symfony/twig-pack: ^1.0
- vimeo/psalm: ^4.23 || ^5.24
Suggests
- composer-runtime-api: Composer v2 is required for seeing version information in metadata
- ext-mongodb: Required for instrumentation of MongoDB
- ext-scoutapm: Recommended for additional recording capability of IO-bound PHP internal functions
- psr/http-client-implementation: Required for Scout Error Reporting
- psr/http-factory-implementation: Required for Scout Error Reporting
- psr/http-message-implementation: Required for Scout Error Reporting
Provides
- 8.13.x-dev
- 8.12.x-dev
- 8.12.0
- 8.11.x-dev
- 8.11.0
- 8.10.x-dev
- 8.10.1
- 8.10.0
- 8.9.x-dev
- 8.9.0
- 8.8.x-dev
- 8.8.1
- 8.8.0
- 8.7.x-dev
- 8.7.0
- 8.6.x-dev
- 8.6.3
- 8.6.2
- 8.6.1
- 8.6.0
- 8.5.x-dev
- 8.5.0
- 8.4.x-dev
- 8.4.1
- 8.4.0
- 8.3.x-dev
- 8.3.2
- 8.3.1
- 8.3.0
- 8.2.x-dev
- 8.2.3
- 8.2.2
- 8.2.1
- 8.2.0
- 8.1.x-dev
- 8.1.0
- v8.0.1
- v8.0.0
- v7.0.0
- v6.7.0
- v6.6.1
- v6.6.0
- v6.5.0
- v6.4.0
- v6.3.0
- v6.2.0
- v6.1.0
- v6.0.1
- v6.0.0
- v6.0.0-alpha1
- v5.3.0
- v5.2.0
- v5.1.0
- v5.0.0
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.0
- v4.0.1
- v4.0.0
- v3.1.0
- v3.0.0
- v2.1.1
- v2.1.0
- v2.0.1
- 2.0.0
- v1.0.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2024-09-10 08:10:30 UTC
README
通过[email protected]联系我们加入测试邀请列表!
使用Scout的PHP APM代理监控PHP应用程序的性能。
一旦安装并配置代理,就会收集详细性能指标和事务跟踪。
要求
PHP版本:7.2+
快速开始
此包是各种框架特定包的基础库。
Laravel、Lumen、Symfony支持
要为特定框架安装ScoutAPM代理,请使用特定包。
直接使用基础库
use Psr\Log\LoggerInterface; use Scoutapm\Agent; use Scoutapm\Config; use Scoutapm\Config\ConfigKey; // It is assumed you are using a PSR Logger /** @var LoggerInterface $psrLoggerImplementation */ $agent = Agent::fromConfig( Config::fromArray([ ConfigKey::APPLICATION_NAME => 'Your application name', ConfigKey::APPLICATION_KEY => 'your scout key', ConfigKey::MONITORING_ENABLED => true, ]), $psrLoggerImplementation ); // If the core agent is not already running, this will download and run it (from /tmp by default) $agent->connect(); // Use $agent to record `webTransaction`, `backgroundTransaction`, `instrument` or `tagRequest` as necessary // Nothing is sent to Scout until you call this - so call this at the end of your request $agent->send();
默认日志级别
默认情况下,该库在设计上非常嘈杂地记录日志 - 这是为了帮助我们在需要时了解出了什么问题。如果您确信一切正常,并且可以在Scout仪表板中看到数据,则可以通过添加以下配置来提高最小日志级别,以设置“最小”日志级别(仅适用于Scout的日志)
use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Scoutapm\Agent; use Scoutapm\Config; use Scoutapm\Config\ConfigKey; /** @var LoggerInterface $psrLoggerImplementation */ $agent = Agent::fromConfig( Config::fromArray([ ConfigKey::APPLICATION_NAME => 'Your application name', ConfigKey::APPLICATION_KEY => 'your scout key', ConfigKey::MONITORING_ENABLED => true, ConfigKey::LOG_LEVEL => LogLevel::ERROR, // <-- add this configuration to reduce logging verbosity ]), $psrLoggerImplementation );
PHP内部函数的监控
您可以通过启用对内部PHP函数执行的额外监控来测量那里的时间。为此,您需要从PECL安装并启用scoutapm
PHP扩展,例如
$ sudo pecl install scoutapm
您可能需要将zend_extension=scoutapm.so
添加到php.ini
中以启用扩展。
启用扩展后,将监控PHP中特定的I/O绑定函数,例如file_get_contents
、file_put_contents
、PDO->exec
等。
或者,您可以从源代码安装。
为Scout启用缓存
由于PHP的无状态和“无共享”架构,Scout库在每个请求上执行一些检查(例如发送有关正在运行系统的某些元数据),这些可以通过在创建代理时为Scout提供PSR-16(简单缓存)实现来消除。
use Doctrine\Common\Cache\RedisCache; use Psr\Log\LoggerInterface; use Roave\DoctrineSimpleCache\SimpleCacheAdapter; use Scoutapm\Agent; use Scoutapm\Config; use Scoutapm\Config\ConfigKey; /** @var LoggerInterface $psrLoggerImplementation */ $yourPsrSimpleCacheImplementation = new SimpleCacheAdapter(new RedisCache()); $agent = Agent::fromConfig( Config::fromArray([ ConfigKey::APPLICATION_NAME => 'Your application name', ConfigKey::APPLICATION_KEY => 'your scout key', ConfigKey::MONITORING_ENABLED => true, ]), $psrLoggerImplementation, $yourPsrSimpleCacheImplementation );
使用提供的PSR-15中间件
从scoutapp/scout-apm-php
版本8.1.0开始,包含PSR-15兼容的中间件,可以在PSR-15中间件兼容的框架中使用,例如Slim或Mezzio。例如,在Slim框架中
// Assumes $app is defined, e.g. an instance of `\Slim\App` $app->add(\Scoutapm\Middleware\ScoutApmMiddleware::class);
您很可能需要在容器中定义\Scoutapm\Middleware\ScoutApmMiddleware::class
。例如,如果您的容器是Laminas ServiceManager,则可以定义一个工厂,如下所示
// Assumes $serviceManager is defined, e.g. an instance of `\Laminas\ServiceManager\ServiceManager` $serviceManager->setFactory( \Scoutapm\Middleware\ScoutApmMiddleware::class, static function (\Psr\Container\ContainerInterface $container) { $logger = $container->get(LoggerInterface::class); $agent = Agent::fromConfig( Config::fromArray([ // any additional array configuration ]), $logger ); return new ScoutApmMiddleware($agent, $logger); } );
文档
有关完整安装和故障排除文档,请访问我们的帮助网站。
支持
请联系我们[email protected]或在存储库中创建问题。