Skip to main content
Integrations

WordPress Integration

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

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 via Composer (recommended for Bedrock-style installs):

composer require perfbase/wordpress

Or install manually by copying the plugin to wp-content/plugins/perfbase and running composer install --no-dev inside the plugin directory.

Activate the plugin in Plugins in the WordPress admin.

Configuration

Configure via Settings > Perfbase in the admin panel. All settings can also be overridden with constants in wp-config.php, and constants take priority over the admin UI.

// wp-config.php
define('PERFBASE_API_KEY', 'your-api-key');
define('PERFBASE_ENABLED', true);

Constants

ConstantDefaultDescription
PERFBASE_ENABLEDfalseMaster on/off switch.
PERFBASE_API_KEY''Your project API key. Required.
PERFBASE_SAMPLE_RATE0.1Fraction of requests 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_DEBUGfalseThrow profiling errors instead of silently logging them.
PERFBASE_LOG_ERRORStrueLog profiling errors via error_log().
PERFBASE_ENVIRONMENTauto-detectedEnvironment name. Falls back to wp_get_environment_type(), then WP_DEBUG.
PERFBASE_APP_VERSIONWordPress versionApplication 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 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: * matches everything

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

What gets profiled

The plugin hooks into WordPress lifecycle events automatically. No code changes required.

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
action{METHOD} {path} (no query string)
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 requests 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 profiling overhead is incurred.

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
  • 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.