예제 #1
0
 /**
  * Hook to record all fron controller events
  * @param Varien_Event_Observer $observer 
  */
 public function controller_action_predispatch(Varien_Event_Observer $observer)
 {
     try {
         if (extension_loaded('newrelic')) {
             $controllerAction = $observer->getControllerAction();
             $request = $controllerAction->getRequest();
             $controllerName = explode("_", $request->getControllerName());
             if (Mage::getStoreConfig('newrelic/settings/ignore_admin_routes') && $request->getRouteName() == 'adminhtml' || $request->getModuleName() == 'admin' || in_array('adminhtml', $controllerName)) {
                 Mage::Helper('newrelic')->setAppName(false);
                 newrelic_ignore_transaction();
                 newrelic_ignore_apdex();
                 return $this;
             }
             if (mage::helper('newrelic')->ignoreModule($request->getModuleName()) === true) {
                 Mage::Helper('newrelic')->setAppName(false);
                 newrelic_ignore_transaction();
                 newrelic_ignore_apdex();
                 return $this;
             }
             if (Mage::getStoreConfig('newrelic/settings/named_transactions')) {
                 $route = $request->getRouteName() . '/' . $request->getControllerName() . '/' . $request->getActionName();
                 if (Mage::getStoreConfig('newrelic/settings/add_module_to_named_transactions')) {
                     $route .= ' (module: ' . $request->getModuleName() . ')';
                 }
                 newrelic_name_transaction($route);
                 Mage::Helper('newrelic')->setAppName(true);
                 return $this;
             }
         }
     } catch (Exception $e) {
         mage::logException($e);
     }
 }
 /**
  * a method other plugins can call to ignore this transaction
  */
 public function ignore()
 {
     newrelic_ignore_transaction();
     newrelic_ignore_apdex();
 }
예제 #3
0
 /**
  * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-ignore-apdex
  */
 public function ignoreApdex()
 {
     if ($this->isLoaded()) {
         newrelic_ignore_apdex();
     }
 }
예제 #4
0
 /**
  * Listen to the event controller_action_predispatch
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function controllerActionPredispatch(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_isEnabled()) {
         return $this;
     }
     $this->_setupAppName();
     $this->_trackControllerAction($observer->getEvent()->getControllerAction());
     // Ignore Apdex for Magento Admin Panel pages
     if ($this->helper->isAdmin()) {
         if (function_exists('newrelic_ignore_apdex')) {
             newrelic_ignore_apdex();
         }
     }
     // Common settings
     if (function_exists('newrelic_capture_params')) {
         newrelic_capture_params(true);
     }
     return $this;
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function ignoreApdex()
 {
     if (!$this->extensionLoaded()) {
         return $this;
     }
     newrelic_ignore_apdex();
     return $this;
 }
예제 #6
0
 public function ignoreApdex()
 {
     return newrelic_ignore_apdex();
 }
예제 #7
0
 /**
  * Do not generate Apdex metrics for this transaction. This is useful when you have either very short or very long
  * transactions (such as file downloads) that can skew your apdex score.
  *
  * @return $this
  */
 public function markIgnoreApdex()
 {
     if ($this->active) {
         newrelic_ignore_apdex();
     }
     return $this;
 }
예제 #8
0
 /**
  * Do not generate Apdex metrics for this transaction.  Useful if you have
  * a very short or very long transaction that can skew your apdex score.
  */
 public function ignoreApdex()
 {
     if ($this->skip()) {
         return;
     }
     newrelic_ignore_apdex();
 }
예제 #9
0
/**
 * Handles the sending of file data to the user's browser, including support for
 * byteranges etc.
 *
 * The $options parameter supports the following keys:
 *  (string|null) preview - send the preview of the file (e.g. "thumb" for a thumbnail)
 *  (string|null) filename - overrides the implicit filename
 *  (bool) dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
 *      if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
 *      you must detect this case when control is returned using connection_aborted. Please not that session is closed
 *      and should not be reopened
 *  (string|null) cacheability - force the cacheability setting of the HTTP response, "private" or "public",
 *      when $lifetime is greater than 0. Cacheability defaults to "private" when logged in as other than guest; otherwise,
 *      defaults to "public".
 *
 * @category files
 * @param stored_file $stored_file local file object
 * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
 * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
 * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
 * @param array $options additional options affecting the file serving
 * @return null script execution stopped unless $options['dontdie'] is true
 */
function send_stored_file($stored_file, $lifetime = null, $filter = 0, $forcedownload = false, array $options = array())
{
    global $CFG, $COURSE;
    if (empty($options['filename'])) {
        $filename = null;
    } else {
        $filename = $options['filename'];
    }
    if (empty($options['dontdie'])) {
        $dontdie = false;
    } else {
        $dontdie = true;
    }
    if ($lifetime === 'default' or is_null($lifetime)) {
        $lifetime = $CFG->filelifetime;
    }
    if (!empty($options['preview'])) {
        // replace the file with its preview
        $fs = get_file_storage();
        $preview_file = $fs->get_file_preview($stored_file, $options['preview']);
        if (!$preview_file) {
            // unable to create a preview of the file, send its default mime icon instead
            if ($options['preview'] === 'tinyicon') {
                $size = 24;
            } else {
                if ($options['preview'] === 'thumb') {
                    $size = 90;
                } else {
                    $size = 256;
                }
            }
            $fileicon = file_file_icon($stored_file, $size);
            send_file($CFG->dirroot . '/pix/' . $fileicon . '.png', basename($fileicon) . '.png');
        } else {
            // preview images have fixed cache lifetime and they ignore forced download
            // (they are generated by GD and therefore they are considered reasonably safe).
            $stored_file = $preview_file;
            $lifetime = DAYSECS;
            $filter = 0;
            $forcedownload = false;
        }
    }
    // handle external resource
    if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) {
        $stored_file->send_file($lifetime, $filter, $forcedownload, $options);
        die;
    }
    if (!$stored_file or $stored_file->is_directory()) {
        // nothing to serve
        if ($dontdie) {
            return;
        }
        die;
    }
    if ($dontdie) {
        ignore_user_abort(true);
    }
    \core\session\manager::write_close();
    // Unlock session during file serving.
    // Use given MIME type if specified, otherwise guess it using mimeinfo.
    // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O
    // only Firefox saves all files locally before opening when content-disposition: attachment stated
    $filename = is_null($filename) ? $stored_file->get_filename() : $filename;
    $isFF = core_useragent::is_firefox();
    // only FF properly tested
    $mimetype = ($forcedownload and !$isFF) ? 'application/x-forcedownload' : ($stored_file->get_mimetype() ? $stored_file->get_mimetype() : mimeinfo('type', $filename));
    // EClass Modification.
    $extns = empty($CFG->largefilenameextentions) ? '.mp4' : $CFG->largefilenameextentions;
    $extns = preg_replace('/\\./', '\\.', $extns);
    $extlist = explode(',', $extns);
    foreach ($extlist as $ext) {
        if (preg_match("/{$ext}\$/", $filename)) {
            // Only check newrelic before its needed so we can test the logic on UAT
            if (extension_loaded('newrelic')) {
                newrelic_ignore_apdex();
            }
            break;
        }
    }
    // End EClass Modification.
    // if user is using IE, urlencode the filename so that multibyte file name will show up correctly on popup
    if (core_useragent::is_ie()) {
        $filename = rawurlencode($filename);
    }
    if ($forcedownload) {
        header('Content-Disposition: attachment; filename="' . $filename . '"');
    } else {
        if ($mimetype !== 'application/x-shockwave-flash') {
            // If this is an swf don't pass content-disposition with filename as this makes the flash player treat the file
            // as an upload and enforces security that may prevent the file from being loaded.
            header('Content-Disposition: inline; filename="' . $filename . '"');
        }
    }
    if ($lifetime > 0) {
        $cacheability = ' public,';
        if (!empty($options['cacheability']) && $options['cacheability'] === 'public') {
            // This file must be cache-able by both browsers and proxies.
            $cacheability = ' public,';
        } else {
            if (!empty($options['cacheability']) && $options['cacheability'] === 'private') {
                // This file must be cache-able only by browsers.
                $cacheability = ' private,';
            } else {
                if (isloggedin() and !isguestuser()) {
                    $cacheability = ' private,';
                }
            }
        }
        header('Cache-Control:' . $cacheability . ' max-age=' . $lifetime . ', no-transform');
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
        header('Pragma: ');
    } else {
        // Do not cache files in proxies and browsers
        if (is_https()) {
            // HTTPS sites - watch out for IE! KB812935 and KB316431.
            header('Cache-Control: private, max-age=10, no-transform');
            header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
            header('Pragma: ');
        } else {
            //normal http - prevent caching at all cost
            header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0, no-transform');
            header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
            header('Pragma: no-cache');
        }
    }
    // Allow cross-origin requests only for Web Services.
    // This allow to receive requests done by Web Workers or webapps in different domains.
    if (WS_SERVER) {
        header('Access-Control-Allow-Origin: *');
    }
    if (empty($filter)) {
        // send the contents
        readfile_accel($stored_file, $mimetype, !$dontdie);
    } else {
        // Try to put the file through filters
        if ($mimetype == 'text/html') {
            $options = new stdClass();
            $options->noclean = true;
            $options->nocache = true;
            // temporary workaround for MDL-5136
            $text = $stored_file->get_content();
            $text = file_modify_html_header($text);
            $output = format_text($text, FORMAT_HTML, $options, $COURSE->id);
            readstring_accel($output, $mimetype, false);
        } else {
            if ($mimetype == 'text/plain' and $filter == 1) {
                // only filter text if filter all files is selected
                $options = new stdClass();
                $options->newlines = false;
                $options->noclean = true;
                $text = $stored_file->get_content();
                $output = '<pre>' . format_text($text, FORMAT_MOODLE, $options, $COURSE->id) . '</pre>';
                readstring_accel($output, $mimetype, false);
            } else {
                // Just send it out raw
                readfile_accel($stored_file, $mimetype, !$dontdie);
            }
        }
    }
    if ($dontdie) {
        return;
    }
    die;
    //no more chars to output!!!
}
예제 #10
0
 /**
  * Ignore the current apdex
  *
  * @return
  */
 public function ignoreApdex()
 {
     if (!$this->hasNewRelic()) {
         return;
     }
     newrelic_ignore_apdex();
 }
예제 #11
0
 /**
  * cron_do_this_hourly
  *
  * @since 1.0
  */
 public function cron_do_this()
 {
     $settings = get_option('rpnrdisable-settings');
     if (isset($settings['enable_cron_job']) && $settings['enable_cron_job'] == 1 || 'test_cronjob' == $_REQUEST['action']) {
         /* Newrelic. transactions. */
         if (extension_loaded('newrelic')) {
             newrelic_ignore_transaction(TRUE);
             newrelic_ignore_apdex(TRUE);
         }
     }
     return true;
 }