Temporal is a distributed, scalable, durable, and highly available orchestration engine used to execute asynchronous long-running business logic in a scalable and resilient way.
Temporal PHP SDK is the framework for authoring Workflows and Activities using PHP language.
Table of contents:
Install the SDK using Composer:
composer require temporal/sdk
The SDK includes two main components: Clients and Workers.
The Clients component is used to start, schedule, and manage Workflows;
the Workers component is used to execute Workflows and Activities.
The Clients component requires the grpc
extension,
and the Workers component requires RoadRunner.
It's recommended to use both components with the protobuf
extension
in production to improve performance.
Client | Worker | |
---|---|---|
RoadRunner | — | required |
ext-grpc | required | — |
ext-protobuf | recommended | recommended |
To download RoadRunner, you can use the following command:
./vendor/bin/rr get
If you are using Spiral, follow the instructions in the documentation.
If you are using the SDK without integrations, the following sections of the documentation may be helpful:
- How to run Worker Processes
- How to develop a basic Workflow
- How to connect a Temporal Client to a Temporal Service
- How to start a Workflow Execution
Note
Check out the repository with examples of using the PHP SDK.
Warning
Since version 2.11.0
,
feature flags were introduced
that change the behavior of the entire PHP worker.
It's recommended to disable deprecated behavior.
The PHP SDK includes a toolkit for testing Workflows. There is documentation and dev guide on how to test a Workflow using Activity mocking.
To ensure the determinism of a Workflow, you can also use the Replay API in tests.
Some recommendations for setting up a development environment:
The Temporal CLI provides direct access to a Temporal Service via the terminal. You can use it to start, stop, inspect and operate on Workflows and Activities, and perform administrative tasks such as Namespace, Schedule, and Task Queue management. The Temporal CLI also includes an embedded Temporal Service suitable for use in development and CI/CD. It includes the Temporal Server, SQLite persistence, and the Temporal Web UI.
Run the following command to start the Temporal Service in development mode:
temporal server start-dev --log-level error
Experimental features:
- Add flags
--dynamic-config-value frontend.enableUpdateWorkflowExecution=true --dynamic-config-value frontend.enableUpdateWorkflowExecutionAsyncAccepted=true
to enable the Workflow Update feature. - Add flag
--dynamic-config-value frontend.enableExecuteMultiOperation=true
to enableupdateWithStart()
feature. - Add flag
--dynamic-config-value system.enableEagerWorkflowStart=true
to enable the Eager Workflow Start feature.
During development, you might need to dump a variable, throw an error trace, or simply look at the call stack.
Since Workflows and Activities run in RoadRunner workers, you cannot use var_dump
,
print_r
, echo
, and other functions that output data to STDOUT.
Instead, use Buggregator along with Trap. In this case, dumps, traces, and logs will be sent via socket to your local Buggregator server, where you can view them in a convenient web interface.
Tip
Trap is a wrapper around symfony/var-dumper
, providing additional debugging capabilities.
Moreover, Trap patches var-dumper for outputting protobuf structures, which is very handy when working with Temporal.
To run Buggregator in Docker, execute the command below and follow the instructions:
docker run --rm -p 8000:8000 -p 1025:1025 -p 9912:9912 -p 9913:9913 ghcr.io/buggregator/server:latest
If you are not using Docker or running PHP code outside a container, you can use Trap as a compact server:
./vendor/bin/trap --ui=8000
Now use the trap()
, tr()
, or dump()
functions to output data to Buggregator.
Web UI will be available at http://localhost:8000
.
Temporal PHP SDK is open-sourced software licensed under the MIT license.