Skip to content

Failure Handling – WP Webhook Framework

Automatic failure monitoring, retry mechanism, and blocking system for webhook reliability.

For email notifications and custom handlers, see Notifications.

Critical Distinction: Retries vs. Blocking

Section titled “Critical Distinction: Retries vs. Blocking”
ConceptScopeConfiguration
RetrySingle webhook eventmax_retries()
BlockingAll webhooks to a URLmax_consecutive_failures()

Retry: Framework automatically retries a single failed webhook event (e.g., “Post #123 update”) with exponential backoff.

In Delivery_Mode::IMMEDIATE, the first attempt runs in the current request and failed retries are still queued in Action Scheduler.

Blocking: Stops all webhooks to a URL after multiple distinct events have failed, preventing resource waste on dead endpoints.

$webhook->max_retries( 3 ) // Retry 3 times before giving up (default: 0)
->timeout( 30 ); // 30 second timeout per attempt

Failed webhooks are retried with increasing delays:

RetryDelay
11 minute
22 minutes
34 minutes
48 minutes

Retry count is tracked in wpwf-retry-count header.

// Static 5-minute delay for all retries
add_filter( 'wpwf_retry_delay', fn() => 300 );
// Faster retries for critical webhooks
add_filter( 'wpwf_retry_base_time', function ( int $base, string $name, int $count ): int {
return 'critical_webhook' === $name ? 10 : $base;
}, 10, 3 );
  1. Webhook fails → Retries attempted according to max_retries()
  2. All retries fail → Failure count incremented for URL
  3. Threshold reached → URL blocked, wpwf_webhook_blocked action fired
  4. Success or expired block window → Counter reset, URL unblocked
$webhook->max_consecutive_failures( 10 ); // Block after 10 failed events (default)
$webhook->max_consecutive_failures( 0 ); // Disable blocking entirely

Disabling blocking: When set to 0:

  • wpwf_webhook_failed action still fires
  • Failure counts are not tracked
  • wpwf_webhook_blocked never fires
  • Webhooks continue regardless of failures

Per-URL state stored in transient wpwf_failures_{md5($url)}:

array(
'failed_webhook_count' => 5, // Failed events (not retry attempts)
'first_failure_at' => 1234567890, // Window start timestamp
'blocked' => true, // Blocked status
'blocked_time' => 1234567890, // Block timestamp
)

Expiration: 1 hour. When a blocked URL is checked after that window, the framework starts a fresh failure window instead of carrying the old failure count forward.

For detailed action documentation, see Hooks and Filters.

ActionWhen Fired
wpwf_webhook_successSuccessful delivery
wpwf_webhook_failedFailed after retries
wpwf_webhook_blockedURL blocked
SettingValue
Failure Threshold10 consecutive events
Block Duration1 hour (auto-unblock)
Retry Attempts0 (disabled)
Retry Base Time60 seconds

Files: src/Dispatcher.php, src/Failure.php, src/Webhook.php

Key methods:

  • Dispatcher::dispatch_immediately() - Sends immediate first attempt and queues retries on failure
  • Dispatcher::schedule_retry_if_applicable() - Schedules retry with backoff
  • Webhook::calculate_retry_delay() - Calculates exponential delay
  • Dispatcher::trigger_webhook_failure() - Tracks failures, fires actions
  • PHP100%