Worker

Unlike HTTP, Temporal uses a different way to configure a worker. Make sure to require the PHP SDK:

$ composer require temporal/sdk

The worker file will look as follows:

<?php

declare(strict_types=1);

use Temporal\WorkerFactory;

ini_set('display_errors', 'stderr');
include "vendor/autoload.php";

// factory initiates and runs task queue specific activity and workflow workers
$factory = WorkerFactory::create();

// Worker that listens on a task queue and hosts both workflow and activity implementations.
$worker = $factory->newWorker(
    'taskQueue',
    \Temporal\Worker\WorkerOptions::new()->withMaxConcurrentActivityExecutionSize(10)
);

// Workflows are stateful. So you need a type to create instances.
$worker->registerWorkflowTypes(MyWorkflow::class);

// Activities are stateless and thread safe. So a shared instance is used.
$worker->registerActivityImplementations(new MyActivity());


// start primary loop
$factory->run();

Read more about Temporal configuration and usage on the official website.

Multi-worker environment

To serve both HTTP and Temporal from the same worker, use the getMode() option of Environment:

Or you may override the server command via:

Last updated

Was this helpful?