1. Go to this page and download the library: Download temporal-php/support library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
temporal-php / support example snippets
use \Temporal\Support\Factory\ActivityStub;
#[\Temporal\Workflow\WorkflowInterface]
class HelloWorkflow {
#[\Temporal\Workflow\WorkflowMethod]
public function run(string $user) {
yield ActivityStub::activity(
class: UserService::class,
startToCloseTimeout: 60,
retryAttempts: 5,
)->getContactEmail($user)->then(
fn (string $email) => ActivityStub::activity(
class: HelloService::class,
startToCloseTimeout: '10 minutes',
retryAttempts: 5,
)->sendHelloEmail($user, $email),
);
}
}
#[\Temporal\Support\Attribute\TaskQueue('my-task-queue')]
#[\Temporal\Support\Attribute\RetryPolicy(attempts: 5)]
#[WorkflowInterface]
interface HelloWorkflow {
#[WorkflowMethod]
public function greet(string $name);
}
$stub = \Temporal\Support\Factory\WorkflowStub::workflow($client, HelloWorkflow::class);
// TaskQueue is now set to 'my-task-queue' and RetryPolicy to 5 attempts
$stub->greet('User');
// You can override the default options
$stub = \Temporal\Support\Factory\WorkflowStub::workflow(
$client,
HelloWorkflow::class,
taskQueue: 'another-task-queue',
retryAttempts: 1,
)->greet('User');
use Temporal\Support\VirtualPromise;
#[\Temporal\Activity\ActivityInterface]
class HelloService {
/**
* @param non-empty-string $name
*
* @return VirtualPromise<non-empty-string>
*/
public function greet(string $name) {
// ...
}
}
#[\Temporal\Workflow\WorkflowInterface]
class WorkflowClass {
#[\Temporal\Workflow\WorkflowMethod]
public function run(string $name) {
$activity = \Temporal\Support\Factory\ActivityStub::activity(HelloService::class);
// IDE will know that $name is a non-empty-string
$name = yield $activity->greet($name);
// ...
}
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.