1. Go to this page and download the library: Download djstarcom/newrelic library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
djstarcom / newrelic example snippets
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();
}
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();