PHP code example of upscale / swoole-newrelic
1. Go to this page and download the library: Download upscale/swoole-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/ */
upscale / swoole-newrelic example snippets
use Upscale\Swoole\Newrelic;
$page = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example page</title>
</head>
<body>
Served by Swoole server
</body>
</html>
HTML;
$server = new \Swoole\Http\Server('127.0.0.1', 8080);
$server->on('request', function ($request, $response) use ($page) {
// PHP processing within request boundary...
usleep(1000 * rand(100, 300));
// Send response
$response->end($page);
// PHP processing outside of request boundary...
usleep(1000 * rand(50, 150));
});
// Real user monitoring (RUM)
$rum = new Newrelic\Browser(new Newrelic\Browser\TransactionFactory());
$rum->instrument($server);
// Application performnce monitoring (APM)
$apm = new Newrelic\Apm(new Newrelic\Apm\TransactionFactory());
$apm->instrument($server);
unset($rum, $apm);
$server->start();