scoutapp / scout-apm-php
Scout Application Performance Monitoring Agent - https://scoutapm.com
Installs: 766 433
Dependents: 6
Suggesters: 0
Security: 0
Stars: 16
Watchers: 5
Forks: 3
Open Issues: 24
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-11-10 08:33:02 UTC
README
Email us at support@ScoutAPM.com to get on the beta invite list!
Monitor the performance of PHP apps with Scout's PHP APM Agent.
Detailed performance metrics and transaction traces are collected once the agent is installed and configured.
Requirements
PHP Versions: 7.2+
Quick Start
This package is the base library for the various framework-specific packages.
Laravel, Lumen, Symfony support
To install the ScoutAPM Agent for a specific framework, use the specific package instead.
Using the base library directly
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();
Default log level
By default, the library is very noisy in logging by design - this is to help us figure out what is going wrong if you need assistance. If you are confident everything is working, and you can see data in your Scout dashboard, then you can increase the minimum log level by adding the following configuration to set the "minimum" log level (which only applies to Scout's logging):
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 );
Monitoring of PHP internal functions
You can enable additional monitoring of internal PHP function executions to measure time taken there. To do so, you need
to install and enable the scoutapm
PHP extension from PECL, for example:
$ sudo pecl install scoutapm
You may need to add zend_extension=scoutapm.so
into your php.ini
to enable the extension.
With the extension enabled, specific IO-bound functions in PHP are monitored, for example file_get_contents
,
file_put_contents
, PDO->exec
and so on.
Alternatively, you can install from source.
Enable caching for Scout
Due to PHP's stateless and "shared-nothing" architecture, the Scout library performs some checks (such as sending some metadata about the running system) on every request. These can be eliminated by giving Scout a PSR-16 (Simple Cache) implementation when creating the agent:
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 );
Using the PSR-15 Middleware provided
Since scoutapp/scout-apm-php
release version 8.1.0, a PSR-15 compatible middleware is included out the box, which may
be used in a PSR-15 middleware-compatible framework, such as Slim or Mezzio. For example, in Slim framework:
// Assumes $app is defined, e.g. an instance of `\Slim\App` $app->add(\Scoutapm\Middleware\ScoutApmMiddleware::class);
You will very likely need to define \Scoutapm\Middleware\ScoutApmMiddleware::class
in your container. For example, if
your container is Laminas ServiceManager, you could define a factory like:
// 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); } );
Documentation
For full installation and troubleshooting documentation, visit our help site.
Support
Please contact us at support@ScoutAPM.com or create an issue in this repo.