2017 © Pedro Peláez
 

library newrelic

NewRelic Tools for PHP

image

djstarcom/newrelic

NewRelic Tools for PHP

  • Sunday, June 10, 2018
  • by StarCOM
  • Repository
  • 1 Watchers
  • 0 Stars
  • 48 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 8 Versions
  • 66 % Grown

The README.md

New Relic Libraries

Build Status Code Coverage, (*1)

New Relic Transaction Library

Use this library to report background jobs or long running scripts to New Relic APM., (*2)

Examples

<?php

namespace Consumers;

class Email
{
    public function sendEmail($recipient, $body, $header)
    {
        //Send email
    }

    public function beforePerform()
    {
        //Before Hook
    }

    public function perform()
    {
        //Perform a job
    }

    public function afterPerform()
    {
        //After Hook
    }
}

namespace Foo\Bar;

use DJStarCOM\NewRelic;
use Consumers;

$consumer = new Consumers\Email();

while (true) {
    $transactionConfig = new NewRelic\Config\TransactionConfig();
    $transactionConfig->applicationName = 'Background Jobs';
    $transactionConfig->transactionName = 'consumer::sendEmail';
    $consumerMonitored = new NewRelic\Transaction($consumer, $transactionConfig);
    $consumerMonitored->sendEmail('Spock', 'James', 'Tiberius');

    $transactionConfig->monitoredMethodName = 'perform';
    $consumerMonitored->beforePerform();
    $consumerMonitored->perform();
    $consumerMonitored->afterPerform();
}

You MUST have an agent configured and running on the server, (*3)

Configuration options

Use TransactionConfig class to personalize your job., (*4)

  • You can use transactionName field to specify the name of each transactions, (*5)

    Defaults to index.php if not specified, (*6)

  • You can use applicationName field to specify the name your application, (*7)

    Defaults to PHP Application if not specified, (*8)

  • You can use monitoredMethodName field to specify only one method to be monitored, (*9)

    If not defined every call to a method will be considered one transaction, (*10)

New Relic Insights Library

Use this library to easily post custom events to New Relic Insights., (*11)

<?php

use DJStarCOM\NewRelic;
use GuzzleHttp\Client;

$client = new Client([
    #You need to change it to your account number
    'base_uri' => 'https://insights-collector.newrelic.com/v1/accounts/99999/'
]);
$this->newRelicInsights = new NewRelic\Insights($client, 'YOUR_KEY_HERE');

$events = new NewRelic\Entity\Insights\EventCollection();

$event = new NewRelic\Entity\Insights\Event();
$event->eventType = 'Purchase';
$event->account = 3;
$event->amount = 259.54;
$events->add($event);

$event2 = new NewRelic\Entity\Insights\Event();
$event2->eventType = 'Purchase';
$event2->account = 4;
$events->add($event2);

$promise = $this->newRelicInsights->sendEvent($events);
$promise->wait();

You can find your key at Insights https://insights.newrelic.com/accounts/99999/manage/add_data, (*12)

Configuring

  • Your base_uri MUST end with trailing slash /
  • You MUST replace 99999 with your account number

Installing

The recommended way to install is through Composer., (*13)

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version:, (*14)

composer.phar require djstarcom/newrelic

The Versions

25/01 2018
21/03 2017

v2.0.0

2.0.0.0

NewRelic Tools for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

18/03 2017

v1.1.0

1.1.0.0

NewRelic Tools for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

01/02 2016

v1.0.0

1.0.0.0

NewRelic Tools for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

12/12 2015

v0.1.1

0.1.1.0

A simple wrapper for NewRelic Insights API

  Sources   Download

MIT

The Requires

 

The Development Requires

11/12 2015

v0.1.0

0.1.0.0

A simple wrapper for NewRelic Insights API

  Sources   Download

MIT

The Requires

 

The Development Requires