diff --git a/docs/develop/php/index.mdx b/docs/develop/php/index.mdx index 447ef6c62a..c47b84e3a2 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](/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..b47c822228 --- /dev/null +++ b/docs/develop/php/set-up.mdx @@ -0,0 +1,423 @@ +--- +id: set-up-your-local-php +title: Set up your local development with the PHP SDK +sidebar_label: Quickstart - Setup +slug: /develop/php/set-up-your-local-php +keywords: + - set up + - getting started + - php sdk +tags: + - PHP SDK + - setup + - getting started +hide_table_of_contents: true +description: Configure your local development environment to get started developing with Temporal +--- + +import { SetupSteps, SetupStep, CodeSnippet } from "@site/src/components/elements/SetupSteps"; +import { CallToAction } from "@site/src/components/elements/CallToAction"; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Quickstart - Setup + +Configure your local development environment to get started developing with Temporal. + + + + + php -v + + +}> + +## Install the PHP + +Make sure you have the PHP installed. + +**If you don't have PHP:** Visit official website to [download and install](https://www.php.net/downloads.php) it. + +### GRPC extension + +GRPC extension is required to work with RoadRunner application server. + +**If you don't have `ext-grpc` installed:** Visit official website to [download and install](https://docs.cloud.google.com/php/docs/reference/help/grpc) it. + + + + + +mkdir temporal-hello-world + + +cd temporal-hello-world + + +composer init -n + + +}> + +## Create a Project + +Now that you have your build tool installed, create a project to manage your dependencies and build your Temporal application. + + + + + + composer require temporal/sdk + + +}> + +## Add Temporal PHP SDK Dependencies + +Now add the Temporal SDK dependencies to your project configuration file. + + + + + +

Download RoadRunner by the following command

+ + ./vendor/bin/rr get + + +
+ +

Install DLoad package manager using Composer

+ + composer require --dev internal/dload + +

Create configuration file named `dload.xml` with the following content

+ + {` + + + + + +`} + +

Finally, download specific RoadRunner binary

+ + ./vendor/bin/dload + +
+
+ +}> + +## Install RoadRunner application server + +Install [RoadRunner application server](https://github.com/roadrunner-server/roadrunner). It does lots of things for you, including: +- managing workflow workers +- managing activity workers +- provides GRPC channel to communicate with Temporal Service through Go SDK + +See [RoadRunner installation instructions](https://docs.roadrunner.dev/docs/general/install) to learn about other installation methods. + +
+ + + + {`rpc: + listen: tcp://127.0.0.1:6001 + + server: + command: "php worker.php" + + temporal: + address: "127.0.0.1:7233" + + logs: + level: info + `} + + +}> + +Create a simple configuration file named `.rr.yaml` with the following content: + + + + + + + +

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: + +
+ + +

Add one more download action to the configuration file

+ + {``} + +

So the final configuration file will looks like the following

+ + {` + + + + + + +`} + + +}> + +### DLoad package manager +Consider using DLoad to delegate all installation and updating processes to the package manager. + +
+ + + +

After installing, open a new Terminal. Keep this running in the background:

+ +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: + +- The Temporal PHP SDK is properly installed +- 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 implementation + +Create an Activity implementation file (`src/GreetingActivity.php`): + +```php +withStartToCloseTimeout(5), + ); + + return yield $activity->greet($name); + } +} +``` + +### 3. Create Worker + +Create a Worker file (`worker.php`, under project root directory): + +```php +newWorker(); + +// Register Workflows +$worker->registerWorkflowTypes(\App\SayHelloWorkflow::class); +// Register Activities +$worker->registerActivity(\App\GreetingActivity::class); + +$factory->run(); +``` + +### 4. Run the Worker + +Previously, we created a Worker that executes Workflow and Activity tasks. + +Now, start the RoadRunner application server to run the Worker: + +```bash +./rr serve +``` + +A Worker polls a Task Queue, that you configure it to poll, looking for work to do. +Once the Worker dequeues a Workflow or Activity task from the Task Queue, it then executes the 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). + +### 5. Execute the Workflow + +Now that your Worker is running, it's time to start a Workflow Execution. + +This final step will validate that everything is working correctly with your file labeled `client.php`. + +Create a separate file called `client.php`: + +```php +newWorkflowStub(\App\SayHelloWorkflow::class); +$result = $workflowStub->sayHello('Temporal'); + +echo "Result: {$result}\n"; +``` + +While your worker is still running, open a new terminal and run: + +```bash +php client.php +``` + +### Verify Success + +If everything is working correctly, you should see: + +- Worker processing the workflow and activity +- Output: `Result: Hello, Temporal!` +- Workflow Execution details in the [Temporal Web UI](http://localhost:8233) + + +

Next: Run your first Temporal Application

+

Create a basic Workflow and run it with the Temporal PHP SDK

+
diff --git a/docs/quickstarts.mdx b/docs/quickstarts.mdx index 5f4860a0ab..343ea6f747 100644 --- a/docs/quickstarts.mdx +++ b/docs/quickstarts.mdx @@ -17,6 +17,7 @@ Choose your language to get started quickly. items={[ { href: "/develop/go/set-up-your-local-go", title: "Go", description: "Install the Go SDK and run a Hello World Workflow in Go." }, { href: "/develop/java/set-up-your-local-java", title: "Java", description: "Install the Java SDK and run a Hello World Workflow in Java." }, + { href: "/develop/php/set-up-your-local-php", title: "PHP", description: "Install the PHP SDK and run a Hello World Workflow in PHP." }, { href: "/develop/ruby/set-up-local-ruby", title: "Ruby", description: "Install the Ruby SDK and run a Hello World Workflow in Ruby." }, { 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." }, diff --git a/sidebars.js b/sidebars.js index 567a21a3fd..6fddde3167 100644 --- a/sidebars.js +++ b/sidebars.js @@ -163,6 +163,7 @@ module.exports = { id: 'develop/php/index', }, items: [ + 'develop/php/set-up-your-local-php', 'develop/php/core-application', 'develop/php/temporal-client', 'develop/php/testing-suite',