首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >New Relic + Wordpress - ignore wp-cron.php

New Relic + Wordpress - ignore wp-cron.php
EN

Stack Overflow用户
提问于 2013-01-01 12:35:27
回答 2查看 1.5K关注 0票数 0

我们已经在我们的服务器上安装了New Relic,以监控我们网站的性能。但是最近我们想从New Relic监控中删除wp-cron.php。

我将以下代码放在wp-cron.php中:

代码语言:javascript
复制
[...]

if ( !defined('ABSPATH') ) {
/** Set up WordPress environment */
require_once('./wp-load.php');
}

if (extension_loaded('newrelic')) {
    newrelic_ignore_transaction();
    newrelic_ignore_apdex();
}

[...]

不幸的是,这个代码不能工作,并且New Relic仍然在报告中显示超时的wordpress cronjob。我们不需要知道在我们的wordpress应用程序中消耗了多少时间。

有人知道怎么把它从新遗物上移走吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-28 20:06:52

我发现为每个应用程序或应用程序中的脚本设置变量的最佳方法是在中将 auto_prepend_file 设置为指向为您设置上述变量的PHP文件。

我使用的代码是published on git,请随意借用/改进/建议。为了简单起见,我也在这里列出它:

代码语言:javascript
复制
###
# NewRelic PHP API central file
# Description: Allows PHP installs using mod-fgcid to set newrelic_set_appname
# Usage: Inside PHP.ini for each vhost in your server,
# point to this script using: auto_prepend_file = "newrelic.php"
# Where you place the script depends on your include_path setting.
# See http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file
# Version: 0.2
# Author http://MATTERmedia.com/
#
# This script is released under the GNU General Public License, version 2 (GPL).
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
###

if (extension_loaded('newrelic')) {
    if (!isset($_SERVER['HTTP_HOST'])) {
        newrelic_set_appname ("Unknown");
        } else {
            # If UseCanonicalName is set to Off, Apache will use (user inputted) HTTP_HOST for SERVER_NAME
            # Best is to rely on HTTP_HOST and validate it against a list of allowed hosts.
            # See http://shiflett.org/blog/2006/mar/server-name-versus-http-host
            $host = strtolower($_SERVER['HTTP_HOST']);
            # Easily disable any vhost from sending data to newrelic.
            $disabled_hosts = array('foo.example.com');
            $valid_hosts = array('bar.example.com');
            # Add a secondary AppName
            $secondary_appname = ';All Virtual Hosts';          
            if ((!in_array($host, $disabled_hosts)) && (in_array($host, $valid_hosts))) {
                    newrelic_set_appname($host.$secondary_appname);
                } else {                    
                    newrelic_ignore_transaction();
                    # technically you wouldn't need to disable_autorum when you ignore_transaction, but it's good practice.
                    newrelic_disable_autorum();
            }           
        }
}

如果您的服务器配置允许每个目录的php.ini,则删除一个新的php.ini,并让auto_prepend_file指向调用newrelic_ignore_transaction()的php文件。

如果您的服务器配置不允许每个目录执行php.ini (例如使用mod_fcgid),请修改建议的代码以检测正在运行的脚本,并在满足该条件时发出newrelic_ignore_transaction()。

票数 3
EN

Stack Overflow用户

发布于 2013-01-02 04:15:00

由于你的问题,我对New Relic一无所知,我发现它似乎是一个非常有用的工具。

环顾四周,我发现Drupal的这段代码与cron作业相关。请参见第68行的TRUE参数。也许你需要那个..。

Drupal module implementing New Relic

代码语言:javascript
复制
57 /**
58 * Implementation of hook_cron().
59 *
60 * This is used to set cron tasks to be not tracked by RPM if so desired.
61 */
62 function new_relic_rpm_cron() {
63     $cron_tracking = variable_get('new_relic_rpm_track_cron', 'norm');
64     if ($cron_tracking == 'bg') {
65         newrelic_background_job(TRUE);
66     }
67     elseif ($cron_tracking == 'ignore') {
68         newrelic_ignore_transaction(TRUE); // pass TRUE to ignore
69     }
70 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14107845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档