/** * @param \Nette\Application\Application $application * @param \Nette\Application\Request $request */ public function __invoke(Application $application, Request $request) { if (PHP_SAPI === 'cli') { newrelic_background_job(TRUE); } $params = $request->getParameters(); $action = $request->getPresenterName(); if (isset($params[$this->actionKey])) { $action = sprintf('%s:%s', $action, $params[$this->actionKey]); } if (!empty($this->map)) { foreach ($this->map as $pattern => $appName) { if ($pattern === '*') { continue; } if (Strings::endsWith($pattern, '*')) { $pattern = Strings::substring($pattern, 0, -1); } if (Strings::startsWith($pattern, ':')) { $pattern = Strings::substring($pattern, 1); } if (Strings::startsWith($action, $pattern)) { \VrtakCZ\NewRelic\Tracy\Bootstrap::setup($appName, $this->license); break; } } } newrelic_name_transaction($action); newrelic_disable_autorum(); }
/** Pass the request to our internal function. * BEWARE! Data are passed as they have been supplied by the user, * they should be carefully handled in the function processing the * request. */ function performAction() { global $wgAjaxExportList, $wgOut, $wgUser; if (empty($this->mode)) { return; } /* * Wikia Change - begin */ Transaction::setEntryPoint(Transaction::ENTRY_POINT_AJAX); Transaction::setAttribute(Transaction::PARAM_FUNCTION, $this->func_name); if (function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } /* * Wikia Change - end */ wfProfileIn(__METHOD__); if (!in_array($this->func_name, $wgAjaxExportList)) { wfDebug(__METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n"); wfHttpError(400, 'Bad Request', "unknown function " . (string) $this->func_name); } elseif (!in_array('read', User::getGroupPermissions(array('*')), true) && !$wgUser->isAllowed('read')) { wfHttpError(403, 'Forbidden', 'You must log in to view pages.'); } else { wfDebug(__METHOD__ . ' dispatching ' . $this->func_name . "\n"); if (strpos($this->func_name, '::') !== false) { $func = explode('::', $this->func_name, 2); } else { $func = $this->func_name; } try { $result = call_user_func_array($func, $this->args); if ($result === false || $result === null) { wfDebug(__METHOD__ . ' ERROR while dispatching ' . $this->func_name . "(" . var_export($this->args, true) . "): " . "no data returned\n"); /* Wikia changes start */ //let's avoid falling back to Iowa (500, 503) in this case, //probably someone is asking for a non-existing dynamic method name wfHttpError(501, 'Not Implemented', "{$this->func_name} returned no data"); } else { if (is_string($result)) { $result = new AjaxResponse($result); } $result->sendHeaders(); $result->printText(); wfDebug(__METHOD__ . ' dispatch complete for ' . $this->func_name . "\n"); } } catch (Exception $e) { wfDebug(__METHOD__ . ' ERROR while dispatching ' . $this->func_name . "(" . var_export($this->args, true) . "): " . get_class($e) . ": " . $e->getMessage() . "\n"); if (!headers_sent()) { wfHttpError(500, 'Internal Error', $e->getMessage()); } else { print $e->getMessage(); } } } $wgOut = null; wfProfileOut(__METHOD__); }
/** * Constructor method. * Sets defaults -- no writing to memache, and a default search indexer instance */ public function __construct() { parent::__construct(); $this->service = new MediaWikiService(); $this->service->setGlobal('AllowMemcacheWrites', false)->setGlobal('AppStripsHtml', true); if (function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } if (function_exists('newrelic_background_job')) { newrelic_background_job(true); } }
public static function handleRequest() { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } // retrieve authentication attempt if ($GLOBALS['Session']->hasAccountLevel('Developer')) { $User = $GLOBALS['Session']->Person; } else { $authEngine = new \Sabre\HTTP\BasicAuth(); $authEngine->setRealm('Develop ' . \Site::$title); $authUserPass = $authEngine->getUserPass(); // try to get user $userClass = \User::$defaultClass; $User = $userClass::getByLogin($authUserPass[0], $authUserPass[1]); // send auth request if login is inadiquate if (!$User || !$User->hasAccountLevel('Developer')) { $authEngine->requireLogin(); die("You must login using a " . \Site::getConfig('primary_hostname') . " account with Developer access\n"); } } // store login to session if (isset($GLOBALS['Session'])) { $GLOBALS['Session'] = $GLOBALS['Session']->changeClass('UserSession', array('PersonID' => $User->ID)); } // detect base path $basePath = array_slice(\Site::$requestPath, 0, count(\Site::$resolvedPath)); // switch to JSON response mode if (static::peekPath() == 'json') { $basePath[] = static::$responseMode = static::shiftPath(); } // handle /develop request if ($_SERVER['REQUEST_METHOD'] == 'GET' && static::getResponseMode() == 'html' && !static::peekPath()) { \RequestHandler::respond('app/ext', array('App' => \Sencha_App::getByName('EmergenceEditor'), 'mode' => 'production', 'title' => 'EmergenceEditor')); } // initial and configure SabreDAV $server = new \Sabre\DAV\Server(new RootCollection()); $server->setBaseUri('/' . join('/', $basePath)); // The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different // directory, if you're storing your data somewhere else. # $lockBackend = new Sabre_DAV_Locks_Backend_FS('/tmp/dav-lock'); # $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend); # $server->addPlugin($lockPlugin); // filter temporary files $server->addPlugin(new \Sabre\DAV\TemporaryFileFilterPlugin('/tmp/dav-tmp')); // ?mount support $server->addPlugin(new \Sabre\DAV\Mount\Plugin()); // emergence :) $server->addPlugin(new \Emergence\DAV\ServerPlugin()); // All we need to do now, is to fire up the server $server->exec(); }
public static function respond($data, $exit = true) { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } $text = json_encode($data); if ($text === false) { throw new Exception('Failed to encode json data, json_last_error=' . json_last_error()); } header('Content-type: application/json', true); print $text; Site::finishRequest($exit); }
function init() { if (defined('DOING_CRON') && DOING_CRON == true) { if ($this->settingsobj->get_setting('ignore_cron')) { newrelic_ignore_transaction(); } } if (defined('DOING_AJAX') && DOING_AJAX == true) { newrelic_disable_autorum(); } if ($this->settingsobj->get_setting('application_id')) { newrelic_set_appname($this->settingsobj->get_setting('application_id')); } if ($this->settingsobj->get_setting('enable_newrelic_errors')) { } }
public function __construct($go_newrelic) { // get the calling object $this->go_newrelic = $go_newrelic; // can't lazy load the config, we need $this->config = $this->go_newrelic->config(); // the license key is typically set elsewhere during the daemon/module installation, // but this allows some potential future where the license key is set in the WP dashboard if (!empty($this->config['license'])) { ini_set('newrelic.license', $this->config['license']); } // END if // set the app name newrelic_set_appname($this->go_newrelic->get_appname()); // basic settings // make sure the config isn't empty or invalid for any of these // ...sanity and validation intentionally skipped for performance reasons ini_set('newrelic.framework', 'wordpress'); ini_set('newrelic.transaction_tracer.detail', $this->config['transaction-tracer-detail']); ini_set('newrelic.error_collector.enabled', $this->config['error-collector-enabled']); if (isset($this->config['capture-params']) && $this->config['capture-params']) { newrelic_capture_params(); } // END if ini_set('newrelic.ignored_params', $this->go_newrelic->config('ignored-params')); // set logging parameters based on request context // ajax responses _cannot_ have RUM in them, for example if (is_admin()) { if (defined('DOING_AJAX') && DOING_AJAX) { newrelic_disable_autorum(); } // END if } elseif (defined('DOING_CRON') && DOING_CRON) { newrelic_disable_autorum(); } else { // add more tracking of the template pieces add_action('template_include', array($this, 'template_include')); } // END else // track the user info add_action('init', array($this, 'init')); }
public static function handleRequest() { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } if (!Site::getConfig('inheritance_key')) { Site::respondUnauthorized('Remote emergence access is disabled'); } elseif (empty($_REQUEST['accessKey']) || $_REQUEST['accessKey'] != Site::getConfig('inheritance_key')) { // attempt to authenticate via developer session if (!UserSession::getFromRequest()->hasAccountLevel('Developer')) { Site::respondUnauthorized('Remote emergence access denied'); } } if ($_REQUEST['remote'] == 'parent') { set_time_limit(1800); $remoteParams = array(); if (!empty($_REQUEST['exclude'])) { $remoteParams['exclude'] = $_REQUEST['exclude']; } HttpProxy::relayRequest(array('url' => static::buildUrl(Site::$pathStack, $remoteParams), 'autoAppend' => false, 'autoQuery' => false, 'timeout' => 500)); } if (empty(Site::$pathStack[0])) { return static::handleTreeRequest(); } elseif ($node = Site::resolvePath(Site::$pathStack)) { if (method_exists($node, 'outputAsResponse')) { $node->outputAsResponse(true); } elseif (is_a($node, 'SiteCollection')) { return static::handleTreeRequest($node); } else { Site::respondBadRequest(); } } else { header('HTTP/1.0 404 Not Found'); die('File not found'); } }
<?php /** * @package XML_Sitemaps */ // This is to prevent issues with New Relics stupid auto injection of code. It's ugly but I don't want // to deal with support requests for other people's wrong code... if (extension_loaded('newrelic') && function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } $xsl = '<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XML Sitemap</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #545353; } table { border: none; border-collapse: collapse;
/** * Prevent the New Relic PHP extension from inserting its JavaScript * for this transaction * * @access public * @return void */ public function disable_autorum() { newrelic_disable_autorum(); }
/** * Disable New Relic's browser metrics * * Removes NR's JavaScript for tracking browser metrics, including page load times, Apdex score, and more. * * Must be called at or before the `template_redirect` action. */ function wpcom_vip_disable_new_relic_js() { if (did_action('template_redirect') && !doing_action('template_redirect')) { _doing_it_wrong(__FUNCTION__, 'New Relic’s browser tracking can only be disabled at or before the `template_redirect` action.', '1.0'); return; } if (function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } }
public function outputAsResponse($includeAuthor = false) { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } if (array_key_exists($this->MIMEType, static::$additionalHeaders)) { $headers = static::$additionalHeaders[$this->MIMEType]; // if value is a string, it's an alias to another headers list if (is_string($headers)) { $headers = static::$additionalHeaders[$headers]; } foreach ($headers as $header) { header($header); } } // use SHA1 for ETag and manifest-based caching header('ETag: ' . $this->SHA1); if (!empty($_GET['_sha1']) && $_GET['_sha1'] == $this->SHA1) { $expires = 60 * 60 * 24 * 365; header('Cache-Control: public, max-age=' . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $expires)); header('Pragma: public'); } // send 304 and exit if current version matches HTTP_IF_* check if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $this->SHA1) { header('HTTP/1.0 304 Not Modified'); exit; } elseif (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $this->Timestamp) { header('HTTP/1.0 304 Not Modified'); exit; } header('Content-Type: ' . $this->MIMEType); header('Content-Length: ' . $this->Size); header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $this->Timestamp)); if ($includeAuthor && $this->Author) { header('Author: ' . $this->Author->EmailRecipient); } readfile($this->RealPath); exit; }
public function removeRumCode($observer) { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } }
function ampforwp_disable_new_relic_scripts($data) { if (!function_exists('newrelic_disable_autorum')) { return $data; } if (function_exists('is_amp_endpoint') && is_amp_endpoint()) { newrelic_disable_autorum(); } return $data; }
/** * Prevents output filter from attempting to insert RUM Javascript. */ public function disableAutorum() { if ($this->skip()) { return; } newrelic_disable_autorum(); }
/** * {@inheritdoc} */ public function disableAutorum() { if ($this->extensionLoaded()) { newrelic_disable_autorum(); } }
public static function serve(WebRequest $request) { $type = $request->getText('type'); try { switch ($type) { case 'one': $builder = new AssetsManagerOneBuilder($request); break; case 'group': $builder = new AssetsManagerGroupBuilder($request); break; case 'groups': $builder = new AssetsManagerGroupsBuilder($request); break; case 'sass': $builder = new AssetsManagerSassBuilder($request); break; case 'sasses': $builder = new AssetsManagerSassesBuilder($request); break; default: Wikia::log(__METHOD__, false, "Unknown type: {$_SERVER['REQUEST_URI']}", true); Wikia::log(__METHOD__, false, AssetsManager::getRequestDetails(), true); throw new Exception('Unknown type.'); } } catch (Exception $e) { header('HTTP/1.1 404 Not Found'); echo $e->getMessage(); return; } // do not log illegal request type (one/group/groups/sass supported only) - not to pollute // logs Transaction::setEntryPoint(Transaction::ENTRY_POINT_ASSETS_MANAGER); if (function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } $headers = array(); if ($builder->getContentType()) { $headers['Content-Type'] = $builder->getContentType(); } // BugId:31327 $headers['Vary'] = $builder->getVary(); $cacheDuration = $builder->getCacheDuration(); // render the response try { $content = $builder->getContent(); } catch (Exception $e) { // return HTTP 503 in case of SASS processing error (BAC-592) // Varnish will cache such response for 5 seconds header('HTTP/1.1 503'); // log exception messages \Wikia\Logger\WikiaLogger::instance()->error('AssetsManagerServer::serve failed', ['type' => $type, 'exception' => $e]); // emit full message on devboxes only global $wgDevelEnvironment; $content = !empty($wgDevelEnvironment) ? $msg = $e->getMessage() : '/* SASS processing failed! */'; } if ($cacheDuration > 0) { $headers['Cache-Control'] = 'public, max-age=' . $cacheDuration['server']; $headers['X-Pass-Cache-Control'] = 'public, max-age=' . $cacheDuration['client']; } $headers['Last-Modified'] = gmdate('D, d M Y H:i:s \\G\\M\\T'); // Add X-Served-By and X-Backend-Response-Time response headers to MediaWiki pages // See BAC-550 for details // @macbre global $wgRequestTime; $headers['X-Served-By'] = wfHostname(); $headers['X-Backend-Response-Time'] = round(microtime(true) - $wgRequestTime, 3); foreach ($headers as $k => $v) { header($k . ': ' . $v); } echo $content; }
/** * {@inheritdoc} */ public function disableAutorum() { if (!$this->extensionLoaded()) { return $this; } newrelic_disable_autorum(); return $this; }
/** * Disable the insertion of the JavaScript for page load timing (RUM) for * the current transaction. * The return value can be different from `true` if the extension is not * loaded. * * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-rum-disable * * @param bool $return * * @return bool */ public function disableAutorum($return = true) { if (!$this->isLoaded()) { return $return; } return newrelic_disable_autorum(); }
public function disableTimings() { return newrelic_disable_autorum(); }
/** * Prevents the output filter from attempting to insert RUM JavaScript for this current transaction. Useful for * AJAX calls, for example. * * RUM: Real User Management @see https://newrelic.com/browser-monitoring * * @return $this */ public function disableAutoRUM() { if ($this->active) { newrelic_disable_autorum(); } return $this; }