Overview
TheSignalMethod attribute marks public methods in your workflow that can receive external signals while the workflow is running. Signals allow external systems or users to send data or commands to an active workflow, enabling dynamic, event-driven behavior.
Basic Usage
How It Works
When you call a signal method on aWorkflowStub, the framework:
- Detects the attribute -
WorkflowStubuses reflection to identify methods marked withSignalMethod(WorkflowStub.php:335-349) - Creates a signal record - The method name and arguments are serialized and stored in the database (WorkflowStub.php:68-72)
- Dispatches the workflow - A
Signaljob is queued to resume the workflow execution (WorkflowStub.php:81) - Replays the signal - When the workflow replays, signals are processed in order
Multiple Signal Methods
A workflow can have multiple signal methods to handle different types of events:Sending Signals
Signals are sent by calling the method on a loaded workflow stub:Signal Methods with Parameters
Signal methods can accept parameters, which are serialized and stored:When to Use SignalMethod
UseSignalMethod when you need to:
- Cancel or pause workflows - Allow external control over workflow execution
- Receive external events - Process webhooks, user actions, or system events
- Implement approval flows - Wait for user approvals or rejections
- Update workflow state - Modify workflow properties during execution
- Handle user input - Build interactive workflows that respond to user actions
Webhook Integration
CombineSignalMethod with the Webhook attribute to expose signal methods as HTTP endpoints:
/webhooks/signal/order-workflow/{workflowId}/cancel (Webhooks.php:93-116).
Differences from QueryMethod and UpdateMethod
- SignalMethod: Modifies workflow state, triggers workflow execution, returns void
- QueryMethod: Reads workflow state without modification, returns immediately
- UpdateMethod: Combines query and signal - returns current state AND queues execution if state was modified
Technical Details
- Target: Methods only (
Attribute::TARGET_METHOD) - Caching: WorkflowStub caches attribute detection for performance (WorkflowStub.php:44)
- Serialization: Arguments are serialized using
Serializer::serialize()(WorkflowStub.php:71) - Execution: Signals are processed through the
Signaljob class - Ordering: Signals are processed in the order they were received
See Also
- QueryMethod - Read workflow state without modification
- UpdateMethod - Read state and optionally trigger execution
- Webhook - Expose workflow methods as HTTP endpoints