|
1 | 1 | # Temporal PHP SDK |
2 | 2 |
|
3 | | -[](https://github.com/temporalio/php-sdk/actions) |
4 | | -[](https://packagist.org/packages/temporal/sdk) |
5 | | -[](https://app.fossa.com/projects/git%2Bgithub.com%2Ftemporalio%2Fsdk-php?ref=badge_shield) |
6 | | - |
7 | | -## Introduction |
8 | | - |
9 | 3 | Temporal is a distributed, scalable, durable, and highly available orchestration |
10 | 4 | engine used to execute asynchronous long-running business logic in a scalable |
11 | 5 | and resilient way. |
12 | 6 |
|
13 | | -"Temporal PHP SDK" is the framework for authoring workflows and activities using |
14 | | -PHP language. |
| 7 | +Temporal PHP SDK is the framework for authoring [Workflows](https://docs.temporal.io/workflows) and [Activities](https://docs.temporal.io/activities) using PHP language. |
| 8 | + |
| 9 | +**Table of contents:** |
| 10 | +- [Get starting](#get-starting) |
| 11 | + - [Installation](#installation) |
| 12 | + - [Usage](#usage) |
| 13 | +- [Testing](#testing) |
| 14 | +- [Dev environment](#dev-environment) |
| 15 | + - [Temporal CLI](#temporal-cli) |
| 16 | + - [Buggregator](#buggregator) |
| 17 | +- [Resources](#resources) |
| 18 | +- [License](#license) |
15 | 19 |
|
16 | | -## Installation |
| 20 | +## Get starting |
17 | 21 |
|
18 | | -SDK is available as composer package and can be installed using the |
19 | | -following command in a root of your project: |
| 22 | +### Installation |
| 23 | + |
| 24 | +Install the SDK using Composer: |
20 | 25 |
|
21 | 26 | ```bash |
22 | 27 | composer require temporal/sdk |
23 | 28 | ``` |
24 | 29 |
|
25 | | -Make sure to install [RoadRunner](https://github.com/spiral/roadrunner) to enable workflow and activity consumption in your PHP workers. |
| 30 | +[](https://packagist.org/packages/temporal/sdk) |
| 31 | +[](https://packagist.org/packages/temporal/sdk) |
| 32 | +[](https://packagist.org/packages/temporal/sdk/stats) |
| 33 | +[](LICENSE.md) |
| 34 | + |
| 35 | +The SDK includes two main components: [Clients](https://docs.temporal.io/develop/php/temporal-clients) and Workers. |
| 36 | +The Clients component is used to start, schedule, and manage Workflows; |
| 37 | +the Workers component is used to execute Workflows and Activities. |
| 38 | + |
| 39 | +The Clients component requires the [`grpc`](https://pecl.php.net/package/grpc) extension, |
| 40 | +and the Workers component requires [RoadRunner](https://roadrunner.dev). |
| 41 | +It's recommended to use both components with the [`protobuf`](https://pecl.php.net/package/protobuf) extension |
| 42 | +in production to improve performance. |
| 43 | + |
| 44 | +| | Client | Worker | |
| 45 | +|--------------|-------------|-------------| |
| 46 | +| RoadRunner | — | required | |
| 47 | +| ext-grpc | required | — | |
| 48 | +| ext-protobuf | recommended | recommended | |
| 49 | + |
| 50 | +To download RoadRunner, you can use the following command: |
| 51 | + |
| 52 | +```bash |
| 53 | +./vendor/bin/rr get |
| 54 | +``` |
26 | 55 |
|
27 | | -## Usage |
| 56 | +### Usage |
28 | 57 |
|
29 | | -See [examples](https://github.com/temporalio/samples-php) to get started. |
| 58 | +If you are using [Spiral](https://github.com/spiral/framework), |
| 59 | +follow the [instructions in the documentation](https://spiral.dev/docs/temporal-configuration/). |
| 60 | + |
| 61 | +If you are using the SDK without integrations, the following sections of the documentation may be helpful: |
| 62 | +- [How to run Worker Processes](https://docs.temporal.io/develop/php/core-application#run-a-dev-worker) |
| 63 | +- [How to develop a basic Workflow](https://docs.temporal.io/develop/php/core-application#develop-workflows) |
| 64 | +- [How to connect a Temporal Client to a Temporal Service](https://docs.temporal.io/develop/php/temporal-clients#connect-to-a-dev-cluster) |
| 65 | +- [How to start a Workflow Execution](https://docs.temporal.io/develop/php/temporal-clients#start-workflow-execution) |
| 66 | + |
| 67 | +> [!NOTE] |
| 68 | +> Check out [the repository with examples](https://github.com/temporalio/samples-php) of using the PHP SDK. |
| 69 | +
|
| 70 | +> [!WARNING] |
| 71 | +> Since version [`2.11.0`](https://github.com/temporalio/sdk-php/releases/tag/v2.11.0), |
| 72 | +> [feature flags](https://github.com/temporalio/sdk-php/blob/master/src/Worker/FeatureFlags.php) were introduced |
| 73 | +> that change the behavior of the entire PHP worker. |
| 74 | +> It's recommended to disable deprecated behavior. |
30 | 75 |
|
31 | 76 | ## Testing |
32 | 77 |
|
33 | | -See [testing manual](testing/Readme.md) to get started. |
| 78 | +The PHP SDK includes a toolkit for testing Workflows. |
| 79 | +There is [documentation](https://docs.temporal.io/develop/php/testing-suite) and [dev guide](testing/Readme.md) on how to test a Workflow using Activity mocking. |
| 80 | + |
| 81 | +To ensure the determinism of a Workflow, |
| 82 | +you can also use the [Replay API in tests](https://docs.temporal.io/develop/php/testing-suite#replay). |
| 83 | + |
| 84 | +## Dev environment |
| 85 | + |
| 86 | +Some recommendations for setting up a development environment: |
| 87 | + |
| 88 | +### Temporal CLI |
| 89 | + |
| 90 | +The [Temporal CLI](https://docs.temporal.io/cli) provides direct access to a Temporal Service via the terminal. |
| 91 | +You can use it to start, stop, inspect and operate on Workflows and Activities, |
| 92 | +and perform administrative tasks such as Namespace, Schedule, and Task Queue management. |
| 93 | +The Temporal CLI also includes an embedded Temporal Service suitable for use in development and CI/CD. |
| 94 | +It includes the Temporal Server, SQLite persistence, and the Temporal Web UI. |
| 95 | + |
| 96 | +Run the following command to start the Temporal Service in development mode: |
| 97 | + |
| 98 | +```bash |
| 99 | +temporal server start-dev --log-level error |
| 100 | +``` |
| 101 | + |
| 102 | +Experimental features: |
| 103 | +- Add flags `--dynamic-config-value frontend.enableUpdateWorkflowExecution=true --dynamic-config-value frontend.enableUpdateWorkflowExecutionAsyncAccepted=true` |
| 104 | +to enable the [Workflow Update feature](https://docs.temporal.io/encyclopedia/workflow-message-passing#sending-updates). |
| 105 | +- Add flag `--dynamic-config-value frontend.enableExecuteMultiOperation=true` to enable [`updateWithStart()` feature](https://php.temporal.io/classes/Temporal-Client-WorkflowClient.html#method_updateWithStart). |
| 106 | +- Add flag `--dynamic-config-value system.enableEagerWorkflowStart=true` to enable the [Eager Workflow Start feature](https://docs.temporal.io/develop/advanced-start-options#eager-start). |
| 107 | + |
| 108 | +### Buggregator |
| 109 | + |
| 110 | +During development, you might need to dump a variable, throw an error trace, or simply look at the call stack. |
| 111 | +Since Workflows and Activities run in RoadRunner workers, you cannot use `var_dump`, |
| 112 | +`print_r`, `echo`, and other functions that output data to STDOUT. |
| 113 | + |
| 114 | +Instead, use [Buggregator](https://buggregator.dev) along with [Trap](https://github.com/buggregator/trap). |
| 115 | +In this case, dumps, traces, and logs will be sent via socket to your local Buggregator server, |
| 116 | +where you can view them in a convenient web interface. |
| 117 | + |
| 118 | +> [!TIP] |
| 119 | +> Trap is a wrapper around `symfony/var-dumper`, providing additional debugging capabilities. |
| 120 | +> Moreover, Trap patches var-dumper for outputting protobuf structures, which is very handy when working with Temporal. |
| 121 | +
|
| 122 | +To run Buggregator in Docker, execute the command below |
| 123 | +and follow the [instructions](https://docs.buggregator.dev/config/var-dumper.html#configuration): |
| 124 | + |
| 125 | +```bash |
| 126 | +docker run --rm -p 8000:8000 -p 1025:1025 -p 9912:9912 -p 9913:9913 ghcr.io/buggregator/server:latest |
| 127 | +``` |
| 128 | + |
| 129 | +If you are not using Docker or running PHP code outside a container, you can use Trap as a compact server: |
| 130 | + |
| 131 | +```bash |
| 132 | +./vendor/bin/trap --ui=8000 |
| 133 | +``` |
| 134 | + |
| 135 | +Now use the `trap()`, `tr()`, or `dump()` functions to output data to Buggregator. |
| 136 | +Web UI will be available at `http://localhost:8000`. |
| 137 | + |
| 138 | +## Resources |
| 139 | + |
| 140 | +Read the docs |
| 141 | +[](https://docs.temporal.io/) |
| 142 | +[](https://docs.temporal.io/develop/php) |
| 143 | +[](https://php.temporal.io/) |
| 144 | + |
| 145 | +Ask a question |
| 146 | +[](https://github.com/temporalio/sdk-php/issues) |
| 147 | +[](https://t.mp/slack) |
| 148 | +[](https://community.temporal.io/tag/php-sdk) |
| 149 | +[](https://discord.gg/FwmDtGQe55) |
| 150 | + |
| 151 | +Stay tuned |
| 152 | +[](https://temporal.io/blog) |
| 153 | +[](https://www.youtube.com/temporalio) |
| 154 | +[](https://x.com/temporalio) |
| 155 | + |
| 156 | +Additionally |
| 157 | +[](https://temporal.io/community) |
| 158 | +[](https://github.com/temporalio/awesome-temporal) |
34 | 159 |
|
35 | | -## Documentation |
36 | | -The documentation on how to use the Temporal PHP SDK and client is [here](https://docs.temporal.io/). |
37 | 160 |
|
38 | 161 | ## License |
39 | | -MIT License, please see [LICENSE](LICENSE.md) for details. |
40 | 162 |
|
| 163 | +Temporal PHP SDK is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
41 | 164 |
|
42 | 165 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Ftemporalio%2Fsdk-php?ref=badge_large) |
0 commit comments