Skip to main content

How to set a Parent Close Policy in PHP

In PHP, a Parent Close Policy is set via the ChildWorkflowOptions object and withParentClosePolicy() method. The possible values can be obtained from the ParentClosePolicy class.

  • POLICY_TERMINATE
  • POLICY_ABANDON
  • POLICY_REQUEST_CANCEL

Then ChildWorkflowOptions object is used to create a new child workflow object:

$child = Workflow::newUntypedChildWorkflowStub(
'child-workflow',
ChildWorkflowOptions::new()
->withParentClosePolicy(ParentClosePolicy::POLICY_ABANDON)
);

yield $child->start();

In the snippet above we:

  1. Create a new untyped child workflow stub with Workflow::newUntypedChildWorkflowStub.
  2. Provide ChildWorkflowOptions object with Parent Close Policy set to ParentClosePolicy::POLICY_ABANDON.
  3. Start Child Workflow Execution asynchronously using yield and method start().

We need yield here to ensure that a Child Workflow Execution starts before the parent closes.