Skip to content
Start writing your first background jobs and workflows in PHP using Zenaton
Branch: master
Clone or download
Latest commit 43cd918 Jun 3, 2019

README.md


Easy Asynchronous Jobs Manager for Developers
Explore the docs »
Website · PHP Library · Tutorial in PHP

Zenaton examples for PHP

Zenaton helps developers to easily run, monitor and orchestrate background jobs on your workers without managing a queuing system. In addition to this, a monitoring dashboard shows you in real-time tasks executions and helps you to handle errors.

This repository contains examples of workflows built with Zenaton. These examples illustrates how Zenaton orchestrates tasks that are executed on different workers.

Installation

Clone this repository

git clone https://github.com/zenaton/examples-php.git; cd examples-php

Then, populate your .env file with your application id and api token found here.

Running on Docker

Simply run

docker-compose build; docker-compose up

You're all set!

While going through the next sections, you will see you have to run examples using commands like the following:

php bin/launch_sequential.php

When using the docker setup, you can run PHP inside the container using the following command instead:

docker-compose exec php bin/launch_sequential.php

Running locally

Install dependencies

composer install

Then, you need to install a Zenaton worker

curl https://install.zenaton.com | sh

And start it, and make it listen to your configuration:

zenaton start; zenaton listen --env=.env --boot=src/bootstrap.php

Your all set!

Your workflows will be processed by your worker, so you won't see anything except the stdout and stderr, respectively zenaton.out and zenaton.err. Look at these files :)

Example 1: Single task execution

This example showcases

  • A single execution of a task.
php bin/launch_single_task.php

Example 2: Sequential tasks execution

This example showcases

  • A sequential execution of three tasks. The second and third tasks are executed only when the previous one is processed.
  • In a sequential task execution, you can get the output of a task. The result of a task can be used by the next one.


Sequential Workflow Diagram

php bin/launch_sequential.php

Example 3: Parallel tasks execution

This example showcases

  • a parallel execution of 2 tasks
  • a third task that is executed only after both first two tasks were processed

Parallel Workflow Diagram

php bin/launch_parallel.php

Example 4: Asynchronous tasks execution

this example showcases

  • Asynchronous executions of Task A and Task B (fire and forget)
  • Then sequential executions of Task C and Task D.

Asynchronous Workflow Diagram

php bin/launch_asynchronous.php

When a task is dispatched asynchronously, the workflow continues its execution without waiting for the task completion. Consequently, a task asynchronous dispatching always returns a null value.

Example 5: Event

This example showcases

  • how to change a workflow's behaviour based on an external event

Event Workflow Diagram

php bin/launch_event.php

Example 6: Wait

This example showcases

  • how the provided Wait task can be used to pause the workflow for a specified duration

Wait Workflow Diagram

php bin/launch_wait.php

Example 7: Wait Event

This example showcases

  • how the provided Wait task can also be used to pause the workflow up to receiving a specific external event

WaitEvent Workflow Diagram

php bin/launch_wait_event.php

Example 8: Recursive Workflow

This example showcases

  • how launching events or workflows directly from orchestrated tasks allows you to schedule recurring workflows
php bin/launch_recursive.php

Example 9: Workflow Versions

This example showcases

  • how to update your workflow implementation, even while previous versions are still running
php bin/launch_version.php

Example 10: Managing Errors

This example showcases

  • how a failed task appear on Zenaton website
  • how to retry a failed task using the retry button

Error Workflow Diagram

php bin/launch_error.php
You can’t perform that action at this time.