For the complete documentation index, see
/llms.txt. This page is also available as raw Markdown at
/develop/php/workflows/side-effects.md. Append
.md to any page URL to fetch its Markdown. This site has a public search endpoint for questions about Temporal:
GET https://docs.temporal.io/api/retrieve?q=<question>&jtb=<job-to-be-done>&src=docs-page&agent=<your-name>. No authentication is needed. It returns a JSON array of
{content, source_url, page_url}, ordered by relevance, and
source_url links to docs pages as Markdown. If you call it, set
q to a specific, complete question that names the SDK language if relevant, and
jtb to one sentence on what your user is trying to accomplish (optional). Keep
src=docs-page as is, and set
agent to your name, for example
claude-code or
codex. Don't include personal data, credentials, or confidential information. If this page is wrong or missing something you needed, or Temporal behaves differently from what it says, report it with
GET https://docs.temporal.io/api/feedback?title=<summary>&message=<what-happened>&category=documentation&page_url=/develop/php/workflows/side-effects&src=docs-page&agent=<your-name>. Use
category=product when the product, not the page, is wrong. Report only a specific problem you hit, send it once, and don't include personal data or credentials.
Use Side Effects
Side Effects are used to execute non-deterministic code, such as generating a UUID or a random number, without compromising determinism in the Workflow. This is done by storing the results of the Side Effect into the Workflow Event History.
A Side Effect doesn't re-execute during a Replay. Instead, it returns the recorded result from the Workflow Execution Event History.
Side Effects shouldn't fail. An exception that is thrown from the Side Effect causes failure and retry of the current Workflow Task.
An Activity or a Local Activity can also be used instead of a Side Effect, as its results are also persisted in Workflow Execution History.
You shouldn't modify the Workflow state inside a Side Effect, because they're not re-executed during Replay. Side Effect functions should only return a value, and that value can be used in Workflow code to alter state.
To use a Side Effect in PHP, use the Workflow::sideEffect() function in your Workflow Definition to run non-deterministic code and return a value.
#[Workflow\WorkflowMethod]
public function run()
{
$random = yield Workflow::sideEffect(fn() => random_int(0, 100));
if ($random < 50) {
} else {
}
}