I have just set up New Relic on my PHP web app. Everything is working great except one thing... All of the transactions show as going through "index.php".
The reason for this because I'm using the Slim framework (there are many alternatives for routing) with URL rewriting so that I can have nice human URLs like "/user/settings" without a folder for every controller and action.
But that still leaves me with index.php
as the name for every New Relic web transaction.
You can use a hook to set the transaction name to the name or pattern of the router.
Here is an example setting it to the pattern:
$app->hook('slim.before.dispatch', function() use ($app) {
newrelic_name_transaction($app->router()->getCurrentRoute()->getPattern());
});
It took me some searching, however I was able to find an answer (available here) related to CodeIgniter.
A little modification made it work for me (with Slim), and I imagine other PHP routers and frameworks will have roughly the same solution:
if (extension_loaded ('newrelic')) {
newrelic_name_transaction($_SERVER['REQUEST_URI']);
}
Edit: to avoid including any GET parameters, use this on the second line:
newrelic_name_transaction(current(explode('?', $_SERVER['REQUEST_URI'])))
Note: Emerson's answer, where he recommends using the route pattern, is a much better option than using the literal URL if you are using Slim.
New Relic now has out-of-the-box support for the Slim Framework starting with version 6.7.0.174 of the PHP Agent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With