Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

ScoutAPM's Base PHP Agent - See README for Laravel, Symfony, and other framework support.

License

NotificationsYou must be signed in to change notification settings

scoutapp/scout-apm-php

Repository files navigation

BuildLatest Stable VersionTotal DownloadsLicense

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.

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

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();

Default log level

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);

Monitoring of PHP internal functions

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.

Enable caching for Scout

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);

Using the PSR-15 Middleware provided

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);    });

Documentation

For full installation and troubleshooting documentation, visit ourhelp site.

Support

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp