Skip to main content
Integrations

WordPress Integration

The Perfbase WordPress plugin provides automatic performance monitoring for WordPress sites, including WooCommerce. Requires WordPress 5.3+ and PHP 7.4 through 8.4.

Installation

Install the Perfbase PHP extension first. This is what does the actual profiling:

bash -c "$(curl -fsSL https://cdn.perfbase.com/install.sh)"

Install the plugin from WordPress.org: Perfbase.

From wp-admin, go to Plugins > Add New and search for Perfbase. You can also download the ZIP from WordPress.org and upload it through the WordPress admin plugin installer.

For source/manual installs, copy the plugin to wp-content/plugins/perfbase and run composer install --no-dev --optimize-autoloader inside the plugin directory.

Activate the plugin in Plugins in the WordPress admin.

Configuration

Configure via Settings > Perfbase in the admin panel. The settings page is the normal setup path for the API key, enabled state, sample rate, advanced transport options, context toggles, feature flags, status-code filtering, and exclusions.

Runtime settings are loaded as defaults, then saved WordPress options, then supported wp-config.php constants. Those constants remain available as hard overrides for managed deployments and take priority over the admin UI for the core keys they map to.

Constants

ConstantDefaultDescription
PERFBASE_ENABLEDfalseMaster on/off switch.
PERFBASE_API_KEY''Your project API key. Required.
PERFBASE_SAMPLE_RATE0.1Fraction of eligible HTTP, AJAX, cron, and WP-CLI executions to profile (0.0–1.0). 0.1 = 10%.
PERFBASE_API_URLhttps://ingress.perfbase.cloudIngestion endpoint.
PERFBASE_TIMEOUT10HTTP timeout in seconds for trace submission.
PERFBASE_PROXY-Optional proxy URL.
PERFBASE_FLAGSDefaultFlagsSDK feature flags bitmask. See Feature flags.
PERFBASE_PROFILE_HTTP_STATUS_CODES200-299,500-599HTTP response status codes that should be submitted. Leave empty to drop all HTTP trace submissions.
PERFBASE_DEBUGfalseThrow profiling errors instead of silently logging them.
PERFBASE_LOG_ERRORStrueLog profiling errors via error_log().
PERFBASE_ENVIRONMENTwp_get_environment_type()Metadata fallback used when the WordPress environment helper is unavailable; then WP_DEBUG maps to development, otherwise production.
PERFBASE_APP_VERSIONWordPress versionMetadata override for the application version recorded on traces.

Context toggles

Control which types of requests are profiled. These are configured in the admin UI:

SettingDefaultDescription
Profile Admin AreaOffProfile wp-admin requests.
Profile AJAX RequestsOnProfile WordPress AJAX requests (admin-ajax.php).
Profile Cron JobsOnProfile WordPress cron executions.
Profile WP-CLI CommandsOffProfile WP-CLI commands.

Include and exclude filters

Control which paths are profiled with include/exclude patterns, configured in the admin UI under Exclusions (one pattern per line):

Default includes: * for http, ajax, cron, and cli

Default excludes: /wp-content/uploads/*, /favicon.ico

Default user agent excludes: bot, crawler, spider (case-insensitive substring match)

Pattern types

  • Glob patterns: /api/*, /wp-admin/edit.php (matched via fnmatch())
  • Regex patterns: /^POST \/wp-json\// (wrapped in forward slashes)
  • Catch-all: * or .* matches everything

Patterns are tested against both the request path and {METHOD} {path} (e.g., GET /my-page).

Span and action naming

The plugin keeps span names low-cardinality and stores the request-specific name in the action attribute:

ContextSpan nameaction attribute
Standard HTTP and enabled admin requestshttp{METHOD} {path} with no query string
AJAX requestsajaxajax.{sanitizedAction} plus ajax.action
WordPress croncroncron.execution
WP-CLI commandscliCommand name plus cli.command

What gets profiled

The plugin hooks into WordPress lifecycle events automatically after it is activated, enabled, and configured with an API key.

Profiling starts from the init hook at priority -999 and stops on shutdown at priority 999. HTTP template context is added on template_redirect, and outbound WordPress HTTP URLs are recorded from pre_http_request.

WordPress lifecycle

  • Theme setup and plugin load phases
  • wp_head and wp_footer milestones
  • Database query count, slow queries (>100ms), and total query time (requires SAVEQUERIES)
  • Memory usage (peak and current)
  • Active plugin count

Content events

  • Post creation and updates (with post type)
  • Comment insertion
  • User login and logout

REST API

  • Route and HTTP method recorded when a REST API request is detected

Outbound HTTP

  • External HTTP request URLs are tracked (scheme + host + path only, no query parameters)

WooCommerce

If WooCommerce is active, the plugin additionally tracks:

  • WooCommerce version
  • Current page type (shop, product, cart, checkout, account)
  • Product ID and type on product pages
  • Cart additions with quantity
  • New order creation

Automatic attributes

Every trace includes these attributes automatically:

AttributeSource
actionHTTP uses {METHOD} {path} with no query string; AJAX, cron, and CLI use the context-specific actions above.
hostnamegethostname()
environmentwp_get_environment_type() or PERFBASE_ENVIRONMENT
app_versionPERFBASE_APP_VERSION or WordPress version
php_versionPHP version
wordpress.versionWordPress version
http_methodRequest method
http_urlFull URL without query string
http_status_codeResponse status code
user_ipClient IP (checks CF-Connecting-IP, X-Forwarded-For, etc.)
user_agentUser agent string
user_idWordPress user ID (if logged in)

WordPress-specific attributes use dot notation (wordpress.version, woocommerce.page). Core trace fields use underscores (http_method, http_status_code).

Sample rate

The sample rate controls what fraction of eligible executions are profiled:

define('PERFBASE_SAMPLE_RATE', 1.0);   // Profile everything (development)
define('PERFBASE_SAMPLE_RATE', 0.1);   // 10% of requests (production)
define('PERFBASE_SAMPLE_RATE', 0.01);  // 1% of requests (high-traffic)

When a request isn’t sampled, no extension trace span is started.

Error handling

Profiling never crashes your site. In production, all profiling errors are caught and optionally logged via error_log(). With PERFBASE_DEBUG enabled, errors are thrown so you can catch configuration issues during development.

If the Perfbase PHP extension is not installed, the plugin detects this gracefully and simply does not profile. A warning is shown on the settings page.

Admin settings page

The settings page at Settings > Perfbase provides:

  • API key and profiling toggle
  • Sample rate configuration
  • Advanced options (API URL, timeout, proxy)
  • Context toggles (admin, AJAX, cron, CLI)
  • Feature flag checkboxes
  • HTTP status-code allowlist
  • Include/exclude path patterns
  • User agent exclusions
  • System information: shows plugin version, PHP version, extension availability, and current profiling status

Uninstalling

Deactivating the plugin stops all profiling immediately. Uninstalling (deleting) the plugin removes all saved settings from the database.