/** * End a New Relic transaction * * @param boolean $ignore Should the statistics NewRelic gathered be discarded? * @return void */ public function stop($ignore = false) { if (!$this->hasNewRelic()) { return; } newrelic_end_transaction($ignore); }
public function endTransaction() { $this->updatePeakMemoryUsage(); if (extension_loaded('newrelic')) { newrelic_end_transaction(); if ($this->output) { echo "\nend transaction\n"; } } $this->started = false; }
public function __construct() { // Execute the healthcheck as quickly as possible if ('/cache-healthcheck?' === $_SERVER['REQUEST_URI']) { if (function_exists('newrelic_end_transaction')) { # See: https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-end-txn newrelic_end_transaction(true); } die('ok'); } add_action('init', array($this, 'init')); }
/** * {@inheritdoc} */ public function process(Message $message, array $options) { if ($this->extensionLoaded) { newrelic_start_transaction($options['new_relic_app_name'], $options['new_relic_license']); newrelic_name_transaction($options['new_relic_transaction_name']); newrelic_background_job(true); } try { $result = $this->processor->process($message, $options); } catch (\Exception $e) { if ($this->extensionLoaded) { newrelic_notice_error(null, $e); newrelic_end_transaction(); } throw $e; } if ($this->extensionLoaded) { newrelic_end_transaction(); } return $result; }
public function endTransaction() { if ($this->getEnabled()) { newrelic_end_transaction(); } }
/** * Stop recording the current transaction and send all of the metrics * gathered thus far to the daemon, unless $ignore is set to `true`. Useful * with queue processing where more than one transactions can occur over * the execution of the script. * * Added in v. 2.3 of the New Relic Agent. * * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-end-txn * @see startTransaction * * @param bool $ignore * * @return bool */ public function endTransaction($ignore = false) { if (!$this->isLoaded()) { return false; } return newrelic_end_transaction($ignore); }
function bapi_create_site() { if (!preg_match('/bapi-signup\\.php$/', $_SERVER['REQUEST_URI'])) { return; } if (extension_loaded('newrelic')) { newrelic_start_transaction('WP InstaSites'); newrelic_name_transaction('create-instasite'); } if (isset($_POST['blogid']) && $_POST['blogid'] != 0) { header('Content-Type: application/javascript'); $d = get_blog_details($_POST['blogid']); if ($d === false) { $new_site = array("status" => "error", "data" => array("errors" => array("blogid_invalid" => "Unable to locate blog with ID: " . $_POST['blogid']), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } switch_to_blog($_POST['blogid']); $blogid = get_current_blog_id(); if ($blogid != $_POST['blogid']) { $new_site = array("status" => "error", "data" => array("errors" => array("blogid_switch_fail" => "Unable to switch to BlogID: " . $_POST['blogid']), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } //Do Update Stuff Here $prefix = $_POST['siteprefix']; $sname = $_POST['sitename']; $tagline = ''; if (isset($_POST['tagline']) && !empty($_POST['tagline'])) { $tagline = $_POST['tagline']; } $apikey = ""; if (isset($_POST['apikey']) && !empty($_POST['apikey'])) { $apikey = $_POST['apikey']; } $username = $_POST['username']; $password = $_POST['password']; $domain = $_SERVER['SERVER_NAME']; $siteurl = $prefix . '.' . $domain; //How to check which domain is used for current service $liveurl = 'http://' . $siteurl; if (isset($_POST['domain']) && !empty($_POST['domain'])) { $liveurl = $_POST['domain']; //bapi_site_cdn_domain } $cf_url = str_replace('http://', '', $liveurl); $cf_origin = str_replace('http://', '', $siteurl); $cf = modify_cf_distro($cf_origin, $cf_url); if ($cf['CreatingDistrib'] === false) { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("cloudfront_distrib" => 'Error Creating CloudFront Distribution'), "message" => $cf['Message'], "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $liveurl = get_site_url(); if (isset($_POST['domain']) && !empty($_POST['domain'])) { $liveurl = $_POST['domain']; //bapi_site_cdn_domain } update_option('bapi_site_cdn_domain', $liveurl); update_option('bapi_cloudfrontid', $cf['Id']); $new_site = array("status" => "success", "data" => array("blog_id" => $_POST['blogid'], "blog_url" => get_site_url())); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $prefix = $_POST['siteprefix']; $sname = $_POST['sitename']; $tagline = ''; if (isset($_POST['tagline']) && !empty($_POST['tagline'])) { $tagline = $_POST['tagline']; } $apikey = ""; if (isset($_POST['apikey']) && !empty($_POST['apikey'])) { $apikey = $_POST['apikey']; } $username = $_POST['username']; $password = $_POST['password']; $domain = $_SERVER['SERVER_NAME']; $siteurl = $prefix . '.' . $domain; //How to check which domain is used for current service $liveurl = 'http://' . $siteurl; if (isset($_POST['domain']) && !empty($_POST['domain'])) { $liveurl = $_POST['domain']; //bapi_site_cdn_domain } $cf_url = str_replace('http://', '', $liveurl); $cf_origin = str_replace('http://', '', $siteurl); if ($apikey == "") { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("apikey_not_set" => "A valid API key is required."), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $cf = create_cf_distro($cf_origin, $cf_url); if ($cf['CreatingDistrib'] === false) { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("cloudfront_distrib" => 'Error Creating CloudFront Distribution'), "message" => $cf['Message'], "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $meta = array('api_key' => $apikey, 'bapi_secureurl' => '', 'bapi_site_cdn_domain' => $liveurl, 'bapi_cloudfronturl' => $cf['DomainName'], 'bapi_cloudfrontid' => $cf['Id'], 'blogdescription' => $tagline, 'bapi_first_look' => 1, 'blog_public' => 1); //http://codex.wordpress.org/Option_Reference#Privacy if (defined('BAPI_BASEURL') && BAPI_BASEURL == 'connect.bookt.biz') { $meta['bapi_secureurl'] = $prefix . '.lodgingcloud.com'; $meta['bapi_baseurl'] = BAPI_BASEURL; } //$siteurl = $prefix.'.imbookingsecure.com'; $u = username_exists($username); if (empty($u)) { $u = wpmu_create_user($username, $password, $username); } //$u = wpmu_create_user($username,$password,$username); if (is_numeric($u)) { $s = wpmu_create_blog($siteurl, '/', $sname, $u, $meta); //$t = wpmu_create_blog('wpmutest.localhost','/','Test1',1); //use this one to force a 'blog_taken' failure. if (is_numeric($s)) { //success switch_to_blog($s); //echo get_site_url();exit(); if (defined('KIGO_SELF_HOSTED') && !KIGO_SELF_HOSTED) { switch_theme(WP_DEFAULT_THEME); } else { switch_theme('instatheme01'); } bapi_wp_site_options(); //Initialize menu and pages //$path = '/bapi.init?p=1'; //$url = get_site_url().$path; //$server_output = file_get_contents($url); //Provide response header('Content-Type: application/javascript'); $new_site = array("status" => "success", "data" => array("blog_id" => $s, "blog_url" => get_site_url())); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } } else { //fail //print_r($s->errors['blog_taken'][0]); exit(); //Not sure if this is the only error returned. Need a more generic message handler. header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => $s); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } } else { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("user_unknown" => "Sorry, the username specified is invalid."), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } exit; }
<?php $loaded = extension_loaded("newrelic"); print "newrelic loaded: " . $loaded . "\n"; print "newrelic_start_transaction exists: " . function_exists("newrelic_start_transaction") . "\n"; print "newrelic_name_transaction exists: " . function_exists("newrelic_name_transaction") . "\n"; print "newrelic_transaction_set_request_url exists: " . function_exists("newrelic_transaction_set_request_url") . "\n"; print "newrelic_transaction_set_threshold exists: " . function_exists("newrelic_transaction_set_threshold") . "\n"; print "newrelic_end_transaction exists: " . function_exists("newrelic_end_transaction") . "\n"; print "newrelic_segment_generic_begin exists: " . function_exists("newrelic_segment_generic_begin") . "\n"; print "newrelic_segment_datastore_begin exists: " . function_exists("newrelic_segment_datastore_begin") . "\n"; print "newrelic_segment_end exists: " . function_exists("newrelic_segment_end") . "\n"; $transaction_id = newrelic_start_transaction(); print "transaction_id: " . $transaction_id . "\n"; $name_error_code = newrelic_name_transaction("my_transaction"); print "name_error_code: " . $name_error_code . "\n"; $request_url_error_code = newrelic_transaction_set_request_url("my/path"); print "request_url_error_code: " . $name_error_code . "\n"; $generic_segment_id = newrelic_segment_generic_begin("my_segment"); print "generic_segment_id: " . $generic_segment_id . "\n"; sleep(2); $datastore_segment_id = newrelic_segment_datastore_begin("my_table", "select"); print "datastore_segment_id: " . $datastore_segment_id . "\n"; sleep(1); $datastore_end_error_code = newrelic_segment_end($datastore_segment_id); print "datastore_end_error_code: " . $datastore_end_error_code . "\n"; $generic_end_error_code = newrelic_segment_end($generic_segment_id); print "generic_end_error_code: " . $generic_end_error_code . "\n"; $end_error_code = newrelic_end_transaction(); print "end_error_code: " . $end_error_code . "\n";
public static function end() { if (extension_loaded('newrelic')) { newrelic_end_transaction(); } }
/** * Despite being similar in name to newrelic_end_of_transaction above, this call * serves a very different purpose. newrelic_end_of_transaction simply marks the * end time of the transaction but takes no other action. The transaction is * still only sent to the daemon when the PHP engine determines that the script * is done executing and is shutting down. This function on the other hand, * causes the current transaction to end immediately, and will ship all of the * metrics gathered thus far to the daemon unless the ignore parameter is set to * true. In effect this call simulates what would happen when PHP terminates the * current transaction. This is most commonly used in command line scripts that * do some form of job queue processing. You would use this call at the end of * processing a single job task, and begin a new transaction (see below) when a * new task is pulled off the queue. * * @param boolean Normally, when you end a transaction you want the metrics that * have been gathered thus far to be recorded. However, there are * times when you may want to end a transaction without doing so. * In this case use the second form of the function and set ignore * to true. * * @since 3.0 */ public function endTransaction($ignore = false) { if ($this->skip()) { return; } newrelic_end_transaction($ignore); }
/** * {@inheritdoc} */ public function endTransaction() { newrelic_end_transaction(false); }