2017 © Pedro Peláez
 

application yii-newrelic

Wrapper around the New Relic PHP API.

image

knyga/yii-newrelic

Wrapper around the New Relic PHP API.

  • Sunday, August 30, 2015
  • by knyga
  • Repository
  • 1 Watchers
  • 0 Stars
  • 155 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yii-newrelic

Yii wrapper around the New Relic PHP API., (*1)

Introduction

yii-newrelic is a wrapper around the New Relic PHP API. Automatic tracking of module/controller/action ID's is supported. Automatic injection of timing header and footer also supported., (*2)

Requirements

  • PHP 5.2+
  • New Relic for PHP
  • One of the following OS's:
    • Linux 2.6+, glibc 2.5+ with NPTL support
    • OpenSolaris 10
    • FreeBSD 7.3+
    • MacOS/X 10.5+
  • Apache 2.2 or 2.4 via mod_php
  • Intel CPU

Installation

1) Install the New Relic PHP driver on your web server per New Relic For PHP instructions., (*3)

2) Install package via composer, (*4)

  • Install Composer to your project root:, (*5)

    curl -sS https://getcomposer.org/installer | php
    
  • Add a composer.json file to your project:, (*6)

    {
      "require": {
        "knyga/yii-newrelic": "dev-master"
      }
    }
    
  • Run the Composer installer:, (*7)

    php composer.phar install
    

3) In main.php add line to define vendor path:, (*8)

Yii::setPathOfAlias('vendor', dirname(__FILE__) . '/../../../vendor');

And add the following to 'components':, (*9)

        'newRelic' => [
            'class' => 'vendor.knyga.yii-newrelic.YiiNewRelic',
        ],
        'clientScript' => [
            'class' => 'vendor.knyga.yii-newrelic.YiiNewRelicClientScript',
        ],

4) If you are using a script that subclasses CClientScript, instead of adding 'clientScript' to your 'components', you will instead need to orphan that extension's script and extend it from YiiNewRelicClientScript instead. To do so, change extends CClientScript to extends YiiNewRelicClientScript, and then add a line before that class declaration that says:, (*10)

    Yii::import('vendor.knyga.yii-newrelic.YiiNewRelicClientScript');

Or add line to import block in your main.php:, (*11)

    'import' => [
        'vendor.knyga.yii-newrelic.YiiNewRelicClientScript'
    ]

5) In main.php, add the following to the top-level array:, (*12)

    'behaviors' => [
        'newRelic' => [
            'class' => 'vendor.knyga.yii-newrelic.behaviors.YiiNewRelicWebAppBehavior',
        ]
    ],

6) Create subclass of CWebApplication, e.g. NewRelicApplication., (*13)

7) In this new class, e.g. NewRelicApplication, add a method::, (*14)

    public function beforeControllerAction($controller, $action) {
        Yii::app()->newRelic->setTransactionName($controller->id, $action->id);
        return parent::beforeControllerAction($controller, $action);
    }

8) To use your new subclassed CWebApplication, modify index.php similar to:, (*15)

    $config=dirname(__FILE__).'/../protected/config/main.php';
    require_once(dirname(__FILE__).'/../yii-1.1.12.b600af/framework/yii.php');
    require_once(dirname(__FILE__).'/../protected/components/system/PromocastApplication.php');
    $app = new NewRelicApplication($config);
    $app->run();

9) In console.php, add the following to 'components':, (*16)

    'newRelic' => [
        'class' => 'vendor.knyga.yii-newrelic.YiiNewRelic',
    ],

10) In console.php, add the following to the top-level array:, (*17)

    'behaviors' => [
        'newRelic' => [
             'class' => 'vendor.knyga.yii-newrelic.behaviors.YiiNewRelicConsoleAppBehavior',
        ],
    ],

Features

  • yii-newrelic automatically detects whether the New Relic PHP extension is properly installed.
  • Automatic association of Yii module/controller/action ID's.
  • Automatic injection of New Relic timing header/footer into your HTML layouts.
  • Console commands also supported.

Usage

  • TODO: Finish docs with use cases with YiiNewRelic API wrapper methods

Known issues and other comments

  • A future release will aim to avoid needing to call YiiNewRelic::nameTransaction() via CWebApplication subclass. This seems to be the only reliable mechanism for determining the actual controller/action in use. An attempt was made to use Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest()) in YiiNewRelicWebAppBehavior, but this does not seem to produce consistent results.
  • Console apps currently only set the class name to YiiNewRelic::nameTransaction().
    A future release will attempt to include the action as well.
  • Your contributions, as always, are greatly appreciated.

License

Modified BSD License https://github.com/gtcode/yii-newrelic, (*18)

The Versions

30/08 2015

dev-master

9999999-dev https://github.com/knyga/yii-newrelic

Wrapper around the New Relic PHP API.

  Sources   Download

GNU

The Requires

  • php >= 5.4
  • lib-curl *

 

by Paul Lowndes

yii newrelic knyga gtcode