Setting Up RUM with PHP
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Setting Up RUM with PHP

  • Dark
    Light
  • PDF

Article summary

This document details how to enable RUM for the APM Profiler in your PHP application running on Linux.

Prerequisites

1. Install the Latest Version of the Agent

Required Agent Version
  • Linux Agent v2.31+
  • PHP Profiler 1.13.0+
PHP on Windows is currently not supported

2. Enable RUM

Follow the RUM Getting Started guide to Enable RUM on your account

3. Setup APM for your Application

Follow the PHP Getting Started Guide to configure the profiler for your specific setup. The profiler will need to be properly configured for RUM to function.

4. Configure the RUM Key

In order to identify the data coming from your application pages is tied to your account, you need to make your RUM Key available to your application. This setting is passed to your application via an environment variable, RETRACE_RUM_KEY.

Linux
Set the RETRACE_RUM_KEY environment variable so that it is available to the application when it launches.

PHP Configuration
Set the stackify.rum_key in your php.ini or on your CGI/FPM settings getting passed on nginx or apache so that it is available to the application.

5. Inject Script into Page

The PHP profiler supports two methods to inject the script into your HTML pages.

Automatic Injection
Automatic Injection is enabled by setting stackify.rum_enabled in your php.ini file or CGI/FPM settings or directives with your webserver.

Manual Injection via APM
The manual injection method requires that an API call to the Profiler is inserted into the HTML files without any quoting of the injectected string. You can call the Stackify\Profiler::insertRumScript() method and require your profiler to be active.

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<?php echo Stackify\Profiler::insertRumScript(); ?>
	<title>Title</title>
…
</head>

This API method is available in stackify-php-apm versions 1.13.0 and greater.

Manual Injection via API
The manual injection method requires that an API call to the Profiler is inserted into the HTML files without any quoting of the injected string. You can call the \Stackify\Utils\Rum::getInstance()->insertRumScript() method and require your profiler to be active at the moment.

Setup:

<?php
/** Requires composer **/
$applicationName = ‘Your Application Name’;
$environment = ‘YourEnvironment’;
$rumKey = ‘YourRumKey’;
 
\Stackify\Utils\Rum::getInstance()->setupConfiguration(
	$applicationName,
	$environment,
	$rumKey
);
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<?php echo \Stackify\Utils\Rum::getInstance()->insertRumScript(); ?>
	<title>Title</title>
…
</head>

This API method is available in stackify/logger versions 1.15.0 and greater.

6. Redeploy your App

Once the previous steps to enable RUM for your account and add the code snippet to your app(s) have been completed, the last step is to deploy the changes to your application.

Viewing RUM Data

Once the following steps have been taken to set up RUM for your apps, data will be reported in the corresponding App Dashboard. To see more information related to what RUM data is presented in the App Dashboard, see the Viewing RUM Data in Retrace help doc.


Was this article helpful?