PHPackages                             roenschg/php-newrelic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. roenschg/php-newrelic

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

roenschg/php-newrelic
=====================

Wrapper for the NewRelic Agent API that allows to send big amounts of custom events reliably.

v2.1.1(4y ago)030.5k1[2 issues](https://github.com/roenschg/php-newrelic/issues)MITPHPPHP ^7.1CI failing

Since Oct 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/roenschg/php-newrelic)[ Packagist](https://packagist.org/packages/roenschg/php-newrelic)[ RSS](/packages/roenschg-php-newrelic/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (3)Versions (9)Used By (0)

php-newrelic
============

[](#php-newrelic)

This package provides a simple and clean wrapper around the newrelic APM agent API and also enables you to send large amounts of custom metrics into newrelic without dropping any data.

Installation
------------

[](#installation)

```
composer require groensch/php-newrelic

```

Basic Usage
-----------

[](#basic-usage)

You have one class that acts as a wrapper for every function that the PHP agent api defines.

```
$newRelic = new Groensch\NewRelic\Handler(new Groensch\NewRelic\CustomEventHandler\PHPAgent());

$newRelic->nameTransaction('MyCustomTransactionName');
$newRelic->recordCustomEvent('eventName', ['count' => 20]);
```

Crossed fingers (Instead of using extension\_loaded('newrelic'))
----------------------------------------------------------------

[](#crossed-fingers-instead-of-using-extension_loadednewrelic)

The `CrossedFingers` handler allows you to use the same methods on environments without a NewRelic extension installed without throwing errors. So instead of doing this if on every line where you want to send events to:

```
if (extension_loaded('newrelic')) { // Ensure PHP agent is available
    newrelic_name_transaction("/Product/view/");
}
```

```
$newRelic = new Groensch\NewRelic\Handler(
    new \Groensch\NewRelic\CustomEventHandler\CrossedFingers(),
    new \Groensch\NewRelic\TransactionHandler\CrossedFingers()
);

$newRelic->nameTransaction('MyCustomTransactionName');
$newRelic->recordCustomEvent('eventName', ['count' => 20]);
```

If the extension does not exist, nothing will be done.

HTTP Bulk sending (Send huge amounts of custom events reliable)
---------------------------------------------------------------

[](#http-bulk-sending-send-huge-amounts-of-custom-events-reliable)

If you need to make sure that you send all the data to NewRelic even if you reach the limits of the agent you can use the CustomEventHandler `AutoBulkHttp`.

Please note that this means you application will be slowed down by the amount of requests you send to NewRelic because of the logged custom events.

The following code shows you how to setup the NewRelicHandler to send the CustomEvents over the API and automaticly pack requests together in bulks.

```
use Groensch\NewRelic\Handler as NewRelicHandler;
use Groensch\NewRelic\HttpInsertApi as NewRelicHttpInsertApi;
use Groensch\NewRelic\CustomEventHandler\AutoBulkHttp as NewRelicCustomEventBulkHttpHandler;

// Configure NewRelic handler
$newRelicHttpApi = new NewRelicHttpInsertApi(NEW_RELIC_API_ACCOUNT_ID, NEW_RELIC_API_INSERT_KEY);
$newRelicCustomEventHandler = new NewRelicCustomEventBulkHttpHandler($newRelicHttpApi);
$newRelic = new NewRelicHandler($newRelicCustomEventHandler);

// Record custom event
$newRelic->recordCustomEvent('test1', ['recorded' => (string) time()]);
$newRelic->recordCustomEvent('test2', ['recorded' => (string) time()]);
```

The `NewRelicHttpInsertApi` is responsible to connect to the InsightAPI and the `NewRelicCustomEventBulkHttpHandler`is responsible to pack custom events together in bulk and is aware of the API limitations.

If the package is big enough it will flush the buffer and send the request to the insights api. The Buffer will be cleared during shutdown of you application as well.

If the data you pass to the method `ecordCustomEvent` is invalid or to big, you will get an Exception.

List of methods
---------------

[](#list-of-methods)

For further information about the methods please see the [NewRelic documentation](https://docs.newrelic.com/docs/agents/php-agent/php-agent-api)

- recordCustomEvent(...)
- addCustomParameter(...)
- backgroundJob(...)
- captureParams(...)
- customMetric(...)
- disableAutorum(...)
- endOfTransaction(...)
- endTransaction(...)
- ignoreApdex(...)
- ignoreTransaction(...)
- nameTransaction(...)
- noticeError(...)
- recordDatastoreSegment(...)
- setAppname(...)
- setUserAttributes(...)
- startTransaction(...)
- getTransactionHandler(...)
- setTransactionHandler(...)

Running Unit-Tests
------------------

[](#running-unit-tests)

```
docker-compose run php composer install
docker-compose run php vendor/bin/phpunit
```

Running Code-Sniffer
--------------------

[](#running-code-sniffer)

```
docker-compose run php composer install
docker-compose run php vendor/bin/phpcs --config-set installed_paths vendor/escapestudios/symfony2-coding-standard
docker-compose run php vendor/bin/phpcs
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 56.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~289 days

Total

4

Last Release

1788d ago

Major Versions

v1.0.0 → v2.0.02020-07-09

PHP version history (2 changes)v1.0.0PHP ^7.0

v2.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1fc3405d47b275fb2e6ced689188aec6652bdca247373e1693920d7a4c50db8?d=identicon)[roenschg](/maintainers/roenschg)

---

Top Contributors

[![roenschg](https://avatars.githubusercontent.com/u/9590236?v=4)](https://github.com/roenschg "roenschg (27 commits)")[![groensch24](https://avatars.githubusercontent.com/u/85474213?v=4)](https://github.com/groensch24 "groensch24 (12 commits)")[![andrejsstepanovs](https://avatars.githubusercontent.com/u/324553?v=4)](https://github.com/andrejsstepanovs "andrejsstepanovs (9 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/roenschg-php-newrelic/health.svg)

```
[![Health](https://phpackages.com/badges/roenschg-php-newrelic/health.svg)](https://phpackages.com/packages/roenschg-php-newrelic)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
