---
title: "Profiling"
description: "Learn more about how to configure our Profiling integration and start profiling your code."
url: https://docs.sentry.io/platforms/php/profiling/
---

# Set Up Profiling for PHP

Profiling for PHP is supported with Sentry PHP SDK version `3.15.0` and above.

With [profiling](https://docs.sentry.io/product/profiling.md), Sentry allows you to collect and analyze performance profiles from real users in production to give you a complete picture of how your application performs in a variety of environments.

Under the hood, we're using Wikipedia's sampling profiler [Excimer](https://github.com/wikimedia/mediawiki-php-excimer). The Excimer PHP extension supports PHP 7.2 and up.

Excimer requires Linux or macOS and doesn't support Windows.

## [Installation](https://docs.sentry.io/platforms/php/profiling.md#installation)

Here's how to install Excimer with a Linux package manager, PECL, or build from a source.

### [Linux Package Manager](https://docs.sentry.io/platforms/php/profiling.md#linux-package-manager)

```bash
apt-get install php-excimer
```

See <https://www.mediawiki.org/wiki/Excimer> for additional distributions.

### [PECL](https://docs.sentry.io/platforms/php/profiling.md#pecl)

```bash
pecl install excimer
```

See <https://pecl.php.net/package/excimer> for more information.

### [Build from source](https://docs.sentry.io/platforms/php/profiling.md#build-from-source)

```bash
git clone https://github.com/wikimedia/mediawiki-php-excimer.git

cd excimer/
phpize && ./configure && make && sudo make install
```

Depending on your environment, you may need to enable the Excimer extension afterwards.

```bash
phpenmod -s fpm excimer
# or
phpenmod -s apache2 excimer
```

## [Enable Continuous Profiling](https://docs.sentry.io/platforms/php/profiling.md#enable-continuous-profiling)

Continuous profiling is available in Sentry PHP SDK version `4.36.0` and above.

The continuous profiler samples your code for as long as it runs. Enable it with [`profile_session_sample_rate`](https://docs.sentry.io/platforms/php/configuration/options.md#profile-session-sample-rate). The sampling decision is made once per profiling session.

### [Manual Lifecycle](https://docs.sentry.io/platforms/php/profiling.md#manual-lifecycle)

By default, you start and stop the profiler yourself. This doesn't require tracing.

```php
\Sentry\init([
    'dsn' => 'https://<key>@o<orgId>.ingest.sentry.io/<projectId>',
    'profile_session_sample_rate' => 1.0,
]);

\Sentry\profiler()->start();

// Run some code here

\Sentry\profiler()->stop();
```

You can also start the profiler before calling `\Sentry\init()`, for example to profile the bootstrap of your application.

In long-running workers, such as FrankenPHP, RoadRunner, or Swoole, start the profiler once and pause it between requests:

```php
\Sentry\profiler()->start();

$handler = static function (): void {
    \Sentry\profiler()->resume();

    // Handle the request

    \Sentry\profiler()->pause();
};

while (frankenphp_handle_request($handler)) {
}
```

### [Trace Lifecycle](https://docs.sentry.io/platforms/php/profiling.md#trace-lifecycle)

Set [`profile_lifecycle`](https://docs.sentry.io/platforms/php/configuration/options.md#profile-lifecycle) to `trace` to run the profiler automatically while a sampled transaction is active:

```php
\Sentry\init([
    'dsn' => 'https://<key>@o<orgId>.ingest.sentry.io/<projectId>',
    'traces_sample_rate' => 1.0,
    'profile_session_sample_rate' => 1.0,
    'profile_lifecycle' => 'trace',
]);
```

## [Enable Transaction-Based Profiling](https://docs.sentry.io/platforms/php/profiling.md#enable-transaction-based-profiling)

Transaction-based profiling captures a profile for each sampled transaction, so tracing has to be enabled. Check out the [tracing setup](https://docs.sentry.io/platforms/php/tracing.md) and [custom instrumentation](https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation.md) documentation for more detailed information.

```php
\Sentry\init([
    'dsn' => 'https://<key>@o<orgId>.ingest.sentry.io/<projectId>',
    'traces_sample_rate' => 1.0,
    // Set a sampling rate for profiling - this is relative to traces_sample_rate
    'profiles_sample_rate' => 1.0,
]);
```

## [Improve Response Time](https://docs.sentry.io/platforms/php/profiling.md#improve-response-time)

Response time is somewhat impacted when you use the performance capabilities in your PHP application, (depending on the `traces_sample_rate` you've configured). This is due to the nature of PHP, where requests are usually sent as part of the process in which you serve your users' response. This affects the time it takes to send a request to Sentry because it's added to your servers' response time.

To offset this and make the addition close to zero, run [Relay](https://docs.sentry.io/product/relay/getting-started.md) locally on the same machine or a local network that can act as a proxy/agent. Doing this will make the PHP process send requests to your local Relay, which will then forward them to Sentry, instead of sending requests to Sentry directly.

To begin using Relay, check out our docs for [getting started](https://docs.sentry.io/product/relay/getting-started.md). We recommend using Relay in `managed` mode (which is the default).

Follow the instructions in the Relay docs to send a test event through Relay to Sentry. Don't forget to update your `DSN` to point to your running Relay instance. After you've set up Relay, you should see a dramatic improvement in how much your server is impacted.

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
