From a6b20838e79614aa86ea41e9be495b58838a9a46 Mon Sep 17 00:00:00 2001 From: Jwahir Sundai Date: Mon, 11 Aug 2025 14:30:52 -0500 Subject: [PATCH 1/2] php quickstart --- docs/develop/php/index.mdx | 1 + docs/develop/php/set-up.mdx | 379 ++++++++++++++++++++++++++++++++++++ sidebars.js | 1 + 3 files changed, 381 insertions(+) create mode 100644 docs/develop/php/set-up.mdx diff --git a/docs/develop/php/index.mdx b/docs/develop/php/index.mdx index e1ab5c5a24..ec265d3128 100644 --- a/docs/develop/php/index.mdx +++ b/docs/develop/php/index.mdx @@ -20,6 +20,7 @@ Build Temporal Applications with the PHP SDK. **Temporal PHP Technical Resources:** +- [PHP SDK Quickstart - Setup Guide](https://docs.temporal.io/develop/php/set-up-your-local-php) - [PHP API Documentation](https://php.temporal.io) - [PHP SDK Code Samples](https://github.com/temporalio/samples-php) - [PHP SDK GitHub](https://github.com/temporalio/sdk-php) diff --git a/docs/develop/php/set-up.mdx b/docs/develop/php/set-up.mdx new file mode 100644 index 0000000000..cf330d24b2 --- /dev/null +++ b/docs/develop/php/set-up.mdx @@ -0,0 +1,379 @@ +--- +id: set-up-your-local-php +title: Set up your local with the PHP SDK +sidebar_label: Quickstart - Setup +description: Configure your local development environment to get started developing with Temporal +keywords: + - set up + - getting started + - PHP sdk +tags: + - PHP guide + - setup + - getting started +hide_table_of_contents: true +--- + +import { SetupSteps, SetupStep, CodeSnippet } from "@site/src/components/elements/SetupSteps"; +import { CallToAction } from "@site/src/components/elements/CallToAction"; + +# Quickstart - Setup + +Configure your local development environment to get started developing with Temporal. + + + + + mkdir helloworld-temporalphp && cd helloworld-temporalphp + + +}> +## Create your project directory + +First, create and navigate into your project directory: + + + + + +composer require temporal/sdk + + +}> + +## Install the Temporal PHP SDK + +Install the PHP SDK using Composer: + +If you don't already have Composer installed, you can install it using Homebrew on macOS: +Or, [follow these instructions](https://getcomposer.org/download/) on the Composer website for Linux or Windows. + + + + + +

See the RoadRunner README file for installation instructions.

+ +

Using Composer, you can install it with the following command:

+ +composer require spiral/roadrunner-cli +./vendor/bin/rr get-binary + +}> + +## Download RoadRunner + +See the RoadRunner README file for installation instructions. +When prompted, enter yes to generate a default `.rr.yaml` file. +You’ll update it later to configure the Temporal plugin. + +Next, you'll configure a local Temporal Service for development. + +
+ + + + + +

Install the Temporal CLI using Homebrew:

+ + brew install temporal + +
+ + +

Download the Temporal CLI archive for your architecture:

+ +

Extract it and add temporal.exe to your PATH.

+
+ + +

Download the Temporal CLI for your architecture:

+ +

Extract the archive and move the temporal binary into your PATH, for example:

+ + sudo mv temporal /usr/local/bin + +
+
+ + +}> + +## Install Temporal CLI and start the development server + +The fastest way to get a development version of the Temporal Service running on your local machine is to use [Temporal CLI](https://docs.temporal.io/cli). + +Choose your operating system to install Temporal CLI: + +
+ + +{`version: "3" + +rpc: +listen: tcp://127.0.0.1:6001 + +server: +command: "php -d display_errors=stderr src/worker.php" + +temporal: +address: \${TEMPORAL_HOST:-localhost}:\${TEMPORAL_PORT:-7233} +activities: +num_workers: 4 + +logs: +level: info +mode: development`} + + +}> + +## Create a RoadRunner configuration file + +To configure RoadRunner Temporal plugin create or open the `.rr.yaml` file in your project directory and make sure it contains the following: + +Replace the default contents of your `.rr.yaml` file with the following configuration, which is required to run the Temporal Worker: +This example shows a minimal .rr.yaml configuration specifically for running a Temporal Worker. + + + + + +

After installing, open a new Terminal window and start the development server:

+ +temporal server start-dev + + +
+

Change the Web UI port

+

The Temporal Web UI may be on a different port in some examples or tutorials. To change the port for the Web UI, use the --ui-port option when starting the server:

+ +temporal server start-dev --ui-port 8080 + +

The Temporal Web UI will now be available at http://localhost:8080.

+
+ + +}> + +## Start the development server + +Once you've installed Temporal CLI and added it to your PATH, open a new Terminal window and run the following command. + +This command starts a local Temporal Service. It starts the Web UI, creates the default Namespace, and uses an in-memory database. + +The Temporal Service will be available on localhost:7233. +The Temporal Web UI will be available at http://localhost:8233. + +Leave the local Temporal Service running as you work through tutorials and other projects. You can stop the Temporal Service at any time by pressing CTRL+C. + +Once you have everything installed, you're ready to build apps with Temporal on your local machine. + +
+
+ +## Run Hello World: Test Your Installation + +Now let's verify your setup is working by creating and running a complete Temporal application with both a Workflow and Activity. + +This test will confirm that: + +- Your PHP SDK installation is working +- Your local Temporal Service is running +- You can successfully create and execute Workflows and Activities +- The communication between components is functioning correctly + +### 1. Create the Activity Interface + +Create an Activity Interface file (GreetingActivityInterface.php) in an Activities subdirectory: + +```php +withScheduleToCloseTimeout(CarbonInterval::seconds(10)) + ); + + return yield $activity->greet($name); + } +} +``` + +### 5. Create and Run the Worker + +With your Activity and Workflow defined, you need a Worker to execute them. A Worker polls a Task Queue, that you configure it to poll, looking for work to do. Once the Worker dequeues the a Workflow or Activity task from the Task Queue, it then executes that task. + +Workers are a crucial part of your Temporal application as they're what actually execute the tasks defined in your Workflows and Activities. +For more information on Workers, see [Understanding Temporal](/evaluate/understanding-temporal#workers) and a [deep dive into Workers](/workers). + +Create a Worker file (worker.php): + +```php +newWorker(); + +$worker->registerWorkflowTypes(\App\Workflows\SayHelloWorkflow::class); +$worker->registerActivityImplementations(new \App\Activities\GreetingActivity()); + +$factory->run(); +``` + +Run the Worker: + +```bash +php worker.php +``` + +### 6. Execute the Workflow + +Now that your Worker is running, it's time to start a Workflow Execution. + +Create a separate file called starter.php: + +```php +newWorkflowStub( + \App\Workflows\SayHelloWorkflowInterface::class, + WorkflowOptions::new() + ->withWorkflowId('say-hello-workflow-id') + ->withTaskQueue('my-task-queue') +); + +$result = $workflow->sayHello('Temporal'); +echo "Workflow result: " . $result . PHP_EOL; +``` + +Then run: + +```bash +php starter.php +``` + +### Verify Success + +If everything is working correctly, you should see: + +- Worker processing the Workflow and Activity +- Output: `Workflow result: Hello Temporal` +- Workflow Execution details in the [Temporal Web UI](http://localhost:8233) + + +

Next: Run your first Temporal Application

+

Learn how to create a basic Workflow and run it with the Temporal PHP SDK

+
diff --git a/sidebars.js b/sidebars.js index 1caad6a524..93ea1df270 100644 --- a/sidebars.js +++ b/sidebars.js @@ -176,6 +176,7 @@ module.exports = { id: "develop/php/index", }, items: [ + "develop/php/set-up-your-local-php", "develop/php/core-application", "develop/php/temporal-clients", "develop/php/testing-suite", From 08c50a0be09ff888532cdc78d26515184dae4c0d Mon Sep 17 00:00:00 2001 From: Jwahir Sundai Date: Wed, 17 Sep 2025 17:37:38 -0500 Subject: [PATCH 2/2] changes based on feedback --- docs/develop/php/set-up.mdx | 75 +++++++++++++++++++++++++++++-------- docs/quickstarts.mdx | 1 + 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/docs/develop/php/set-up.mdx b/docs/develop/php/set-up.mdx index cf330d24b2..e7cf29ccf1 100644 --- a/docs/develop/php/set-up.mdx +++ b/docs/develop/php/set-up.mdx @@ -54,23 +54,42 @@ Or, [follow these instructions](https://getcomposer.org/download/) on the Compos + +sudo pecl install grpc + + +

Then verify the extension is loaded:

+ +php -m | grep grpc + + +}> -

See the RoadRunner README file for installation instructions.

+## Install the gRPC extension + +The Temporal PHP SDK requires the gRPC extension for client operations. +Install it using PECL: + +**Note:** After installation, you may need to restart your terminal or web server. +Use `php --ini` to find your php.ini location if needed. + +
+ + + +

The Temporal PHP SDK includes RoadRunner for running workers. +You'll create a configuration file for it.

-

Using Composer, you can install it with the following command:

-composer require spiral/roadrunner-cli -./vendor/bin/rr get-binary +touch .rr.yaml }> -## Download RoadRunner +## Create RoadRunner Configuration -See the RoadRunner README file for installation instructions. -When prompted, enter yes to generate a default `.rr.yaml` file. -You’ll update it later to configure the Temporal plugin. -Next, you'll configure a local Temporal Service for development. +Create a `.rr.yaml` file in your project directory - you'll configure it in the next step.
@@ -123,19 +142,19 @@ Choose your operating system to install Temporal CLI: {`version: "3" rpc: -listen: tcp://127.0.0.1:6001 + listen: tcp://127.0.0.1:6001 server: -command: "php -d display_errors=stderr src/worker.php" + command: "php -d display_errors=stderr src/worker.php" temporal: -address: \${TEMPORAL_HOST:-localhost}:\${TEMPORAL_PORT:-7233} -activities: -num_workers: 4 + address: \${TEMPORAL_HOST:-localhost}:\${TEMPORAL_PORT:-7233} + activities: + num_workers: 4 logs: -level: info -mode: development`} + level: info + mode: development`} }> @@ -198,6 +217,30 @@ This test will confirm that: - You can successfully create and execute Workflows and Activities - The communication between components is functioning correctly +### 0. Configure Composer Autoloading + +First, configure Composer to autoload your classes. +Add the following to your `composer.json` file above the "require" section: + +```json +{ + "autoload": { + "psr-4": { + "App\\": "src/" + } + }, + "require": { + "temporal/sdk": "^2.0" + } +} +``` + +Then run: + +```bash +composer dump-autoload -o --classmap-authoritative +``` + ### 1. Create the Activity Interface Create an Activity Interface file (GreetingActivityInterface.php) in an Activities subdirectory: diff --git a/docs/quickstarts.mdx b/docs/quickstarts.mdx index 5f4860a0ab..53561dde20 100644 --- a/docs/quickstarts.mdx +++ b/docs/quickstarts.mdx @@ -21,6 +21,7 @@ Choose your language to get started quickly. { href: "/develop/python/set-up-your-local-python", title: "Python", description: "Install the Python SDK and run a Hello World Workflow in Python." }, { href: "/develop/typescript/set-up-your-local-typescript", title: "TypeScript", description: "Install the TypeScript SDK and run a Hello World Workflow in TypeScript." }, { href: "/develop/dotnet/set-up-your-local-dotnet", title: ".NET", description: "Install the .NET SDK and run a Hello World Workflow in C#." }, + { href: "/develop/php/set-up-your-local-php", title: "PHP", description: "Install the PHP SDK and run a Hello World Workflow in PHP." }, ]} />