I'm a programmer specialising in performant and scalable systems using PHP and Ruby and cooking


Published:
On PHP | NewRelic

Renaming your PHP application for NewRelic

This information is available in NewRelic's documentation but as it's not that obvious to find and I've used it a lot I'd thought sharing it again couldn't hurt.

When you install the NewRelic PHP extension defaults to collecting all metrics against "PHP Application" which is particularily helpful when you have multiple PHP applications per account. To seperate metrics and make it easier to track individual applications you can set the application name. You can do this in the php.ini to set it for all php applications which is fine if you only have 1 applications per server, however when hosting multiple applications you'll want to set this per applications.

In a script included in all parts of the application (Symfony2: web/app.php, Wordpress: index.php) and as early as possible in the application (idealy before any config etc is loaded to catch errors there properly) add these lines:

if (extension_loaded('newrelic')) {  
  newrelic_set_appname($name);
}

Where $name is the name of your application, for example in the case of the Versionable website $name = "Versionable Website"