Unofficial PHP SDK for Inngest - Build event-driven workflows with durable execution.
composer require dealnews/inngest-php-sdk- PHP 8.1 or higher
- ext-json
- ext-hash
- ✅ Event-driven workflows - Trigger functions from events
- ✅ Durable execution - Automatic retries and step memoization
- ✅ Step functions - Break work into retriable blocks
- ✅ Sleep & delays - Pause execution for minutes, hours, or days
- ✅ Wait for events - Coordinate across async workflows
- ✅ Function invocation - Call other Inngest functions
- ✅ Cron triggers - Schedule recurring tasks
- ✅ Concurrency control - Limit parallel execution
- ✅ Priority queues - Dynamic execution ordering
- ✅ Debounce - Delay execution until events settle
- ✅ Rate limiting - Hard limit on function runs per time period
- ✅ Throttling - FIFO queueing with burst support
- ✅ Singleton - Ensure only one run executes at a time
- ✅ Send events from steps - Emit events as retriable steps
- ✅ HTTP fetch steps - Make durable HTTP requests as retriable steps
- ✅ Checkpointing - Execute multiple steps per invocation for efficiency
- ✅ Middleware - Hook into function execution lifecycle
- ✅ Dev mode - Local development with Inngest dev server
- ✅ Type safety - Full PHP 8.1+ type declarations
use DealNews\Inngest\Client\Inngest;
$client = new Inngest('my-app');use DealNews\Inngest\Function\InngestFunction;
use DealNews\Inngest\Function\TriggerEvent;
$function = new InngestFunction(
id: 'hello-world',
handler: function ($ctx) {
$name = $ctx->getEvent()->getData()['name'] ?? 'World';
return ['message' => "Hello, {$name}!"];
},
triggers: [
new TriggerEvent('demo/hello')
],
name: 'Hello World Function'
);
$client->registerFunction($function);use DealNews\Inngest\Http\ServeHandler;
$handler = new ServeHandler($client, '/api/inngest');
// In your framework (e.g., Laravel, Symfony):
$response = $handler->handle(
method: $_SERVER['REQUEST_METHOD'],
path: $_SERVER['REQUEST_URI'],
headers: getallheaders(),
body: file_get_contents('php://input'),
query: $_GET
);
http_response_code($response['status']);
foreach ($response['headers'] as $key => $value) {
header("{$key}: {$value}");
}
echo $response['body'];use DealNews\Inngest\Event\Event;
$client->send(new Event(
name: 'demo/hello',
data: ['name' => 'PHP Developer']
));Steps enable you to break your function into retriable blocks:
use DealNews\Inngest\Function\InngestFunction;
use DealNews\Inngest\Function\TriggerEvent;
$function = new InngestFunction(
id: 'process-order',
handler: function ($ctx) {
$step = $ctx->getStep();
// Each step is individually retriable
$order = $step->run('fetch-order', function () use ($ctx) {
return fetchOrder($ctx->getEvent()->getData()['order_id']);
});
$step->run('charge-customer', function () use ($order) {
return chargeCustomer($order);
});
// Sleep for a duration
$step->sleep('wait-for-fulfillment', '1h');
$step->run('send-confirmation', function () use ($order) {
return sendConfirmationEmail($order);
});
return ['status' => 'complete'];
},
triggers: [new TriggerEvent('order/created')]
);$payment = $step->waitForEvent(
id: 'wait-for-payment',
event: 'payment/completed',
timeout: '1h',
if: 'event.data.order_id == async.data.order_id'
);$result = $step->invoke(
id: 'call-function',
function_id: 'my-app-other-function',
payload: ['data' => ['foo' => 'bar']]
);$step->sendEvent('notify-team', new Event(
name: 'order/fulfilled',
data: ['order_id' => $order['id']]
));$response = $step->fetch(
id: 'get-user',
url: 'https://api.example.com/users/123',
method: 'GET',
headers: ['Authorization' => 'Bearer ' . $token]
);The SDK uses environment variables for configuration:
# Required for production
INNGEST_SIGNING_KEY=signkey-prod-xxxxx
INNGEST_EVENT_KEY=your-event-key
# Optional
INNGEST_SIGNING_KEY_FALLBACK=signkey-prod-yyyyy
INNGEST_ENV=production
INNGEST_DEV=1 # Enable dev server mode
INNGEST_API_BASE_URL=https://api.inngest.com
INNGEST_EVENT_API_BASE_URL=https://inn.gs
INNGEST_SERVE_ORIGIN=https://yourapp.com
INNGEST_SERVE_PATH=/api/inngest
INNGEST_LOG_LEVEL=debugOr configure programmatically:
use DealNews\Inngest\Config\Config;
$config = new Config(
event_key: 'your-event-key',
signing_key: 'signkey-prod-xxxxx',
is_dev: false
);
$client = new Inngest('my-app', $config);use DealNews\Inngest\Error\NonRetriableError;
$function = new InngestFunction(
id: 'validate-data',
handler: function ($ctx) {
if (!isValid($ctx->getEvent()->getData())) {
throw new NonRetriableError('Invalid data');
}
return ['status' => 'ok'];
},
triggers: [new TriggerEvent('data/received')]
);use DealNews\Inngest\Error\RetryAfterError;
throw new RetryAfterError('Rate limited', retry_after: 60); // Retry after 60 secondsuse DealNews\Inngest\Function\TriggerCron;
$function = new InngestFunction(
id: 'daily-report',
handler: function ($ctx) {
generateDailyReport();
return ['status' => 'complete'];
},
triggers: [
new TriggerCron('0 0 * * *') // Every day at midnight
]
);Limit how many steps can run simultaneously across all function runs. Useful for rate-limiting external APIs, managing resources, or preventing overwhelming downstream services.
use DealNews\Inngest\Function\Concurrency;
$function = new InngestFunction(
id: 'process-data',
handler: function ($ctx) {
// Function logic
},
triggers: [new TriggerEvent('data/process')],
concurrency: [
new Concurrency(limit: 10) // Max 10 concurrent steps
]
);// Limit to 2 concurrent runs per user
$function = new InngestFunction(
id: 'user-task',
handler: function ($ctx) {
// Process user-specific task
},
triggers: [new TriggerEvent('user/task')],
concurrency: [
new Concurrency(
limit: 2,
key: 'event.data.user_id' // Group by user ID
)
]
);// Set both regional and account-wide limits
$function = new InngestFunction(
id: 'process-orders',
handler: function ($ctx) {
// Process order
},
triggers: [new TriggerEvent('order/created')],
concurrency: [
// Limit per region
new Concurrency(
limit: 5,
key: 'event.data.region',
scope: 'fn' // Per function (default)
),
// Overall account limit
new Concurrency(
limit: 100,
scope: 'account' // Across all environments
)
]
);- limit: Maximum concurrent steps (0 = unlimited)
- key: Expression to group concurrency (e.g.,
event.data.user_id,event.data.region) - scope: Where the limit applies
fn(default): Per functionenv: Per environment (production, staging, etc.)account: Across entire account
Heads-up: Maximum of 2 concurrency configurations per function.
See examples/concurrency.php for more examples.
Dynamically prioritize function runs based on event data. Higher priority runs execute ahead of lower priority ones within the same function queue.
use DealNews\Inngest\Function\Priority;
$function = new InngestFunction(
id: 'process-task',
handler: function ($ctx) {
// Function logic
},
triggers: [new TriggerEvent('task/process')],
priority: new Priority(
run: 'event.data.priority' // Use priority from event
)
);// Prioritize enterprise customers
$function = new InngestFunction(
id: 'ai-generate-summary',
handler: function ($ctx) {
// Generate AI summary
},
triggers: [new TriggerEvent('ai/summary.requested')],
priority: new Priority(
// Enterprise accounts run up to 120 seconds ahead
run: 'event.data.account_type == "enterprise" ? 120 : 0'
)
);// Delay free tier users
$function = new InngestFunction(
id: 'process-report',
handler: function ($ctx) {
// Generate report
},
triggers: [new TriggerEvent('report/generate')],
priority: new Priority(
// Free plan users delayed by 60 seconds
run: 'event.data.plan == "free" ? -60 : 0'
)
);- run: CEL expression that returns an integer priority factor
- Range:
-600to600seconds (enforced by Inngest) - Positive values: Run ahead of jobs enqueued up to N seconds ago
- Negative values: Delay execution by N seconds
0: No priority (default queue position)
- Range:
How it works: When a function run is enqueued, Inngest evaluates the expression using the event data. The result adjusts the run's position in the queue relative to other pending runs.
Heads-up:
- Most useful when combined with concurrency limits (jobs wait in queue)
- Invalid expressions evaluate to
0(no priority) - Out-of-range values are automatically clipped by Inngest
See Inngest Priority Documentation for more details.
Delay function execution until events stop arriving for a specified period. Prevents wasted work when functions might be triggered rapidly in succession (user input, webhook floods, frequent updates).
The function runs once using the last event received as input data.
use DealNews\Inngest\Function\Debounce;
$function = new InngestFunction(
id: 'process-user-input',
handler: function ($ctx) {
$text = $ctx->getEvent()->getData()['text'];
// Process final input after user stops typing
return saveUserInput($text);
},
triggers: [new TriggerEvent('user/input')],
debounce: new Debounce(
period: '30s' // Wait 30 seconds after last event
)
);// Separate debounce window for each user
$function = new InngestFunction(
id: 'sync-user-data',
handler: function ($ctx) {
$user_id = $ctx->getEvent()->getData()['user_id'];
// Sync data once updates stop for this user
return syncUserData($user_id);
},
triggers: [new TriggerEvent('user/updated')],
debounce: new Debounce(
period: '5m',
key: 'event.data.user_id' // Each user has own debounce
)
);// Process webhooks, but force execution after maximum wait
$function = new InngestFunction(
id: 'process-webhook',
handler: function ($ctx) {
$data = $ctx->getEvent()->getData();
// Process either when events stop OR timeout reached
return processWebhook($data);
},
triggers: [new TriggerEvent('webhook/received')],
debounce: new Debounce(
period: '1m', // Wait 1 minute after last event
timeout: '10m' // Force run after 10 minutes max
)
);// Debounce per customer and region combination
$function = new InngestFunction(
id: 'aggregate-metrics',
handler: function ($ctx) {
$data = $ctx->getEvent()->getData();
return aggregateMetrics($data['customer_id'], $data['region']);
},
triggers: [new TriggerEvent('metrics/collected')],
debounce: new Debounce(
period: '2m',
key: 'event.data.customer_id + "-" + event.data.region'
)
);- period (required): Time to wait after last event
- Format:
<number><unit>where unit iss,m,h, ord - Range:
1sto7d(168 hours) - Examples:
30s,5m,2h,7d
- Format:
- key (optional): CEL expression to group debounce windows
- Each unique key value gets its own debounce period
- Examples:
event.data.user_id,event.data.region
- timeout (optional): Maximum wait time before forcing execution
- Same format and range as period
- Ensures function eventually runs even if events keep arriving
How it works:
- First event starts the debounce period
- Each new matching event resets the period timer
- Function runs when period expires with no new events
- If timeout is set, function runs after timeout regardless of new events
Use cases:
- User input: Wait for user to stop typing before processing
- Webhook processing: Batch rapid webhook updates into single run
- Data synchronization: Use latest data after updates settle
- Rate limiting: Prevent overwhelming downstream services
Heads-up:
- Cannot combine debounce with batching
- Function receives only the last event, not all events
- Use rate limiting if you need the first event instead of last
See examples/debounce.php for more examples and Inngest Debounce Documentation for details.
Ensure only a single run of a function (or per unique key) is executing at a time. Prevents duplicate work, race conditions, and ensures sequential processing of events.
use DealNews\Inngest\Function\Singleton;
$function = new InngestFunction(
id: 'data-sync',
handler: function ($ctx) {
// Sync data with third-party API
// Only one sync can run at a time
return syncDataWithAPI();
},
triggers: [new TriggerEvent('sync/start')],
singleton: new Singleton(
mode: 'skip' // Skip new runs if one is executing
)
);// Each user has their own singleton rule
$function = new InngestFunction(
id: 'process-user-data',
handler: function ($ctx) {
$user_id = $ctx->getEvent()->getData()['user_id'];
// Process user data (only one run per user at a time)
return processUserData($user_id);
},
triggers: [new TriggerEvent('user/data.updated')],
singleton: new Singleton(
mode: 'skip',
key: 'event.data.user_id' // Separate singleton per user
)
);// Always process the latest event
$function = new InngestFunction(
id: 'sync-latest-profile',
handler: function ($ctx) {
$user_id = $ctx->getEvent()->getData()['user_id'];
// Cancel old sync and start new one with latest data
return syncUserProfile($user_id);
},
triggers: [new TriggerEvent('profile/updated')],
singleton: new Singleton(
mode: 'cancel', // Cancel existing run, start new one
key: 'event.data.user_id'
)
);// Singleton per customer and region combination
$function = new InngestFunction(
id: 'generate-report',
handler: function ($ctx) {
$data = $ctx->getEvent()->getData();
return generateReport($data['customer_id'], $data['region']);
},
triggers: [new TriggerEvent('report/generate')],
singleton: new Singleton(
mode: 'skip',
key: 'event.data.customer_id + "-" + event.data.region'
)
);- mode (required): Behavior when new run arrives
"skip": Skip new runs if another is already executing"cancel": Cancel existing run and start the new one
- key (optional): CEL expression to group singleton behavior
- Each unique key value gets its own singleton rule
- Examples:
event.data.user_id,event.data.tenant_id
Skip Mode:
- First event starts the function run
- While running, new matching events are skipped/discarded
- Function completes with first event's data
- Next event can then start a new run
Cancel Mode:
- First event starts the function run
- New matching event cancels the in-progress run
- New run starts immediately with latest event
- Rapid events may cause some to be skipped (debounce-like)
Use Skip Mode when:
- Preventing duplicate work (only need to process once)
- Protecting expensive operations (AI, heavy compute)
- Sequential processing required (database migrations)
- Resource limits (third-party API rate limits)
Use Cancel Mode when:
- Latest data matters most (user profile updates)
- Older data becomes stale (real-time dashboards)
- Want to process most recent event (search queries)
- Data synchronization: Third-party API syncs (skip mode)
- AI processing: Expensive computations (skip mode)
- Profile updates: Always use latest data (cancel mode)
- Report generation: One report at a time per customer (skip + key)
- Database migrations: Sequential execution required (skip mode)
Works with:
- ✅ Debounce
- ✅ Priority
- ✅ Rate limiting
- ✅ Throttling
Does not work with:
- ❌ Batching (singleton incompatible)
⚠️ Concurrency (singleton implies concurrency=1)
Heads-up:
- Failed functions still skip new runs during retry
- Cancel mode with rapid events may skip some (not all are cancelled)
- Singleton ensures "at most one" run, not "exactly one"
See examples/singleton.php for more examples and Inngest Singleton Documentation for details.
Set a hard limit on how many function runs can start within a time period. Events exceeding the limit are skipped (not queued). Uses the Generic Cell Rate Algorithm (GCRA) for smooth distribution.
use DealNews\Inngest\Function\RateLimit;
$function = new InngestFunction(
id: 'api-request',
handler: function ($ctx) {
// Call external API
// Maximum 100 calls per hour
return callExternalAPI($ctx->getEvent()->getData());
},
triggers: [new TriggerEvent('api/request')],
rate_limit: new RateLimit(
limit: 100,
period: '1h'
)
);// Each user has their own rate limit
$function = new InngestFunction(
id: 'user-api-request',
handler: function ($ctx) {
$user_id = $ctx->getEvent()->getData()['user_id'];
// Limit: 10 requests per 30 minutes per user
return processUserRequest($user_id);
},
triggers: [new TriggerEvent('user/api.request')],
rate_limit: new RateLimit(
limit: 10,
period: '30m',
key: 'event.data.user_id'
)
);// Complex key expression
$function = new InngestFunction(
id: 'process-webhook',
handler: function ($ctx) {
$data = $ctx->getEvent()->getData();
return processWebhook($data);
},
triggers: [new TriggerEvent('webhook/received')],
rate_limit: new RateLimit(
limit: 50,
period: '1h',
key: 'event.data.customer_id + "-" + event.data.region'
)
);- limit (required): Maximum runs per period
- Must be >= 1
- period (required): Time window
- Format:
<number><unit>where unit iss,m, orh - Range:
1sto24h(does NOT support days) - Examples:
30s,10m,2h,24h
- Format:
- key (optional): CEL expression to group rate limits
- Each unique key value has its own independent limit
- Examples:
event.data.user_id,event.data.api_key
- Uses Generic Cell Rate Algorithm (GCRA) for smooth distribution
- Events exceeding limit are skipped/discarded (lossy behavior)
- Period begins when first matching event is received
- Each unique key value has its own rate limit tracker
- External API limits: Enforce third-party API rate limits
- Resource protection: Prevent overwhelming downstream services
- Cost control: Limit expensive operations (AI, compute)
- Abuse prevention: Per-user/API key rate limiting
Works with:
- ✅ Concurrency, priority, debounce, singleton, throttling
Does not work with:
- ❌ Batching (not yet implemented)
Heads-up:
- Events exceeding limit are permanently lost (use throttling for lossless queueing)
- Rate limit is enforced server-side by Inngest
- Maximum period is 24 hours (for longer periods, use throttling with up to 7 days)
See examples/rate-limit.php for more examples and Inngest Rate Limiting Documentation for details.
Limit how many function runs can start within a time period, with excess runs enqueued for future execution (FIFO). Unlike rate limiting which skips events, throttling ensures no data loss.
use DealNews\Inngest\Function\Throttle;
$function = new InngestFunction(
id: 'process-job',
handler: function ($ctx) {
// Process job at controlled rate
// Maximum 10 jobs per hour (excess are queued)
return processJob($ctx->getEvent()->getData());
},
triggers: [new TriggerEvent('job/created')],
throttle: new Throttle(
limit: 10,
period: '1h'
)
);// Allow bursts above base limit
$function = new InngestFunction(
id: 'api-sync',
handler: function ($ctx) {
// Base: 100/hour, can burst up to 110/hour
return syncWithAPI($ctx->getEvent()->getData());
},
triggers: [new TriggerEvent('sync/request')],
throttle: new Throttle(
limit: 100,
period: '1h',
burst: 10 // Allow 10 extra runs during spikes
)
);// Each user has their own throttle
$function = new InngestFunction(
id: 'user-report',
handler: function ($ctx) {
$user_id = $ctx->getEvent()->getData()['user_id'];
// Limit: 5 reports per 30 minutes per user
return generateReport($user_id);
},
triggers: [new TriggerEvent('report/generate')],
throttle: new Throttle(
limit: 5,
period: '30m',
key: 'event.data.user_id'
)
);// Throttle per customer and region
$function = new InngestFunction(
id: 'aggregate-data',
handler: function ($ctx) {
$data = $ctx->getEvent()->getData();
return aggregateData($data);
},
triggers: [new TriggerEvent('data/received')],
throttle: new Throttle(
limit: 100,
period: '1h',
burst: 20,
key: 'event.data.customer_id + "-" + event.data.region'
)
);- limit (required): Base number of runs per period
- Must be >= 1
- period (required): Time window
- Format:
<number><unit>where unit iss,m,h, ord - Range:
1sto7d(supports days unlike rate limiting) - Examples:
30s,10m,2h,7d
- Format:
- burst (optional): Extra runs allowed during spikes
- Must be >= 0 (default: 0, no bursting)
- Total capacity: limit + burst
- Example: limit=10, burst=5 allows 15 runs per period
- key (optional): CEL expression to group throttles
- Each unique key value has its own throttle
- Examples:
event.data.user_id,event.data.tenant_id
- Uses Generic Cell Rate Algorithm (GCRA)
- Breaks period into windows based on limit
- Events exceeding limit are enqueued (FIFO) for future execution
- Burst parameter allows temporary spikes
- Each unique key value has its own throttle tracker
When the limit is reached:
- Excess events are added to a queue (First In, First Out)
- As capacity becomes available, queued events execute in order
- No events are lost (unlike rate limiting)
The burst parameter handles traffic spikes:
- Without burst (burst=0): Admits exactly
limitruns per period - With burst (burst>0): Admits up to
limit + burstruns per period - Example:
limit: 100, burst: 10allows 110 runs per hour during spikes - Useful for: API burst allowances, handling temporary traffic increases
- API rate limit compliance: Match external API limits with burst allowance
- Smooth traffic spikes: Evenly distribute execution over time
- Background job processing: Control processing rate without data loss
- Resource management: Prevent overwhelming services while queuing excess
- Cost control: Limit expensive operations but process all eventually
| Feature | Throttle | Rate Limit |
|---|---|---|
| Excess events | Enqueued (FIFO) | Skipped |
| Data loss | No ✅ | Yes (lossy) ❌ |
| Max period | 7 days | 24 hours |
| Burst support | Yes ✅ | No |
| Use case | Process all events | Hard limits |
Works with:
- ✅ Concurrency, priority, debounce, singleton, rate limiting
Does not work with:
- ❌ Batching (not yet implemented)
Heads-up:
- All events are eventually processed (FIFO queue)
- Burst capacity refreshes each period
- Throttle is enforced server-side by Inngest
- Supports longer periods (7 days) vs rate limiting (24 hours max)
See examples/throttle.php for more examples and Inngest Throttling Documentation for details.
Checkpointing allows the SDK to execute multiple steps within a single HTTP invocation by persisting step results to Inngest in the background. This reduces round-trip overhead for functions with many fast steps.
use DealNews\Inngest\Function\Checkpoint;
$function = new InngestFunction(
id: 'bulk-processor',
handler: function ($ctx) {
$step = $ctx->getStep();
// Steps execute without yielding after each one
$a = $step->run('step-a', fn() => computeA());
$b = $step->run('step-b', fn() => computeB());
return ['a' => $a, 'b' => $b];
},
triggers: [new TriggerEvent('bulk/process')],
checkpointing: new Checkpoint()
);Three static presets are available:
Checkpoint::safe() // Checkpoint after every step (most durable, default)
Checkpoint::performant() // Buffer up to 1000 steps (fastest, least durable)
Checkpoint::blended() // Buffer 3 steps or 3 seconds, whichever comes firstOr configure manually:
new Checkpoint(
bufferedSteps: 10, // Steps to buffer before flushing
maxInterval: '5s', // Flush at least every 5 seconds
maxRuntime: '30s' // Maximum total execution time per invocation
)Middleware hooks into the function execution lifecycle for logging, monitoring, input/output transformation, and event interception.
use DealNews\Inngest\Middleware\AbstractMiddleware;
use DealNews\Inngest\Function\FunctionContext;
class LoggingMiddleware extends AbstractMiddleware
{
public function beforeExecution(FunctionContext $ctx): void
{
error_log('Executing: ' . $ctx->getEvent()->getName());
}
public function afterExecution(FunctionContext $ctx): void
{
error_log('Completed: ' . $ctx->getEvent()->getName());
}
}
$client = new Inngest('my-app');
$client->addMiddleware(new LoggingMiddleware());Available lifecycle hooks (all optional):
| Hook | When it fires |
|---|---|
transformInput() |
Before handler; can mutate memoized step data |
afterMemoization() |
When first encountering an unmemoized step |
beforeExecution() |
Immediately before handler runs |
afterExecution() |
Immediately after handler returns |
transformOutput() |
Before response building; can mutate result/error |
beforeResponse() |
Before building the response array |
beforeSendEvents() |
Before events are sent via the client |
afterSendEvents() |
After events have been sent |
The SDK follows PSR standards and uses:
- snake_case for variables and properties
- camelCase for method names
- Protected visibility by default
composer test