- Notifications
You must be signed in to change notification settings - Fork3
ScoutAPM's Base PHP Agent - See README for Laravel, Symfony, and other framework support.
License
scoutapp/scout-apm-php
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Email us atsupport@ScoutAPM.com to get on the beta invite list!
Monitor the performance of PHP apps with Scout'sPHP APM Agent.
Detailed performance metrics and transaction traces are collected once the agent is installed and configured.
PHP Versions: 7.2+
This package is the base library for the various framework-specific packages.
To install the ScoutAPM Agent for a specific framework, use the specific package instead.
usePsr\Log\LoggerInterface;useScoutapm\Agent;useScoutapm\Config;useScoutapm\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();
By default, the library isvery noisy in logging by design - this is to help us figure out what is going wrong if youneed assistance. If you are confident everything is working, and you can see data in your Scout dashboard, then youcan increase the minimum log level by adding the following configuration to set the "minimum" log level (whichonlyapplies to Scout's logging):
usePsr\Log\LoggerInterface;usePsr\Log\LogLevel;useScoutapm\Agent;useScoutapm\Config;useScoutapm\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);
You can enable additional monitoring of internal PHP function executions to measure time taken there. To do so, you needto install and enable thescoutapm
PHP extension from PECL, for example:
$ sudo pecl install scoutapm
You may need to addzend_extension=scoutapm.so
into yourphp.ini
to enable the extension.
With the extension enabled, specific IO-bound functions in PHP are monitored, for examplefile_get_contents
,file_put_contents
,PDO->exec
and so on.
Alternatively, you caninstall from source.
Due to PHP's stateless and "shared-nothing" architecture, the Scout library performs some checks (such as sending somemetadata about the running system) on every request. These can be eliminated by giving Scout a PSR-16 (Simple Cache)implementation when creating the agent:
useDoctrine\Common\Cache\RedisCache;usePsr\Log\LoggerInterface;useRoave\DoctrineSimpleCache\SimpleCacheAdapter;useScoutapm\Agent;useScoutapm\Config;useScoutapm\Config\ConfigKey;/** @var LoggerInterface $psrLoggerImplementation */$yourPsrSimpleCacheImplementation =newSimpleCacheAdapter(newRedisCache());$agent = Agent::fromConfig( Config::fromArray([ ConfigKey::APPLICATION_NAME =>'Your application name', ConfigKey::APPLICATION_KEY =>'your scout key', ConfigKey::MONITORING_ENABLED =>true, ]),$psrLoggerImplementation,$yourPsrSimpleCacheImplementation);
Sincescoutapp/scout-apm-php
release version 8.1.0, a PSR-15 compatible middleware is included out the box, which maybe 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, ifyour 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,staticfunction (\Psr\Container\ContainerInterface$container) {$logger =$container->get(LoggerInterface::class);$agent = Agent::fromConfig( Config::fromArray([// any additional array configuration ]),$logger );returnnewScoutApmMiddleware($agent,$logger); });
For full installation and troubleshooting documentation, visit ourhelp site.
Please contact us atsupport@ScoutAPM.com or create an issue in this repo.
About
ScoutAPM's Base PHP Agent - See README for Laravel, Symfony, and other framework support.