PHP
PHP (or Hypertext Preprocessor) is an open source, general-purpose scripting language that's well-suited for web development. It can be embedded into HTML.
On this page, we get you up and running with Sentry's PHP SDK, automatically reporting errors and exceptions in your application. The SDK provides support for PHP 7.2 or later. If you're using a previous version of the PHP SDK, you can access the legacy SDK documentation.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
Related Guides
Sentry captures data by using an SDK within your application’s runtime. Our SDKs are platform-specific and allow Sentry to have a deep understanding of how your application works.
Install the SDK using Composer.
composer require sentry/sentry
Install the Excimer extension via PECL:
pecl install excimer
The Excimer PHP extension supports PHP 7.2 and up. Excimer requires Linux or macOS and doesn't support Windows. For additional ways to install Excimer, see docs.
To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.
\Sentry\init([
'dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0' ,
// Specify a fixed sample rate
'traces_sample_rate' => 1.0,
// Set a sampling rate for profiling - this is relative to traces_sample_rate
'profiles_sample_rate' => 1.0,
]);
In PHP you can either capture a caught exception or capture the last error with captureLastError.
try {
$this->functionFailsForSure();
} catch (\Throwable $exception) {
\Sentry\captureException($exception);
}
If you're using Laravel's Forge platform to provision and deploy your PHP application, you can create a Sentry organization through Forge.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").