PHPackages                             emerick42/kairoi-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. emerick42/kairoi-php

ActiveLibrary[Queues &amp; Workers](/categories/queues)

emerick42/kairoi-php
====================

The official PHP client for Kairoi, a Dynamic, Accurate and Scalable Time-based Job Scheduler.

v0.1.0-alpha(4y ago)81.6kMITPHPPHP ^8.0.10CI failing

Since Oct 20Pushed 4y ago2 watchersCompare

[ Source](https://github.com/emerick42/kairoi-php)[ Packagist](https://packagist.org/packages/emerick42/kairoi-php)[ RSS](/packages/emerick42-kairoi-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Kairoi-PHP
==========

[](#kairoi-php)

A PHP client for [Kairoi](https://github.com/emerick42/kairoi), a Dynamic, Accurate and Scalable Time-based Job Scheduler.

Quick Words
-----------

[](#quick-words)

Before trying to use this library, you should be familiar with Kairoi's core concepts. If it's not yet the case, you can start by reading the [Kairoi Official documentation](https://github.com/emerick42/kairoi/blob/master/docs/index.md).

About this library, its main goal is to provide an **easy-to-use**, **object-oriented**, and **low-level** programmable interface to communicate with Kairoi servers in PHP. It abstracts managing socket connections with servers, encoding and decoding messages using the [Kairoi Client Protocol](https://github.com/emerick42/kairoi/blob/master/docs/client-protocol.md), and handling [Kairoi Instructions](https://github.com/emerick42/kairoi/blob/master/docs/instructions.md). It should be noted that this library is designed to be used with Dependency Injection Containers, and the associated "Actor/Message" pattern as a specialization of Object-Oriented Programming. While this can definitely be considered as a constraint, it allows Kairoi-PHP to be highly extensible.

The usual workflow to work with Kairoi and this library is the following:

1. *Rules and runners are configured for an application, defining how jobs will be processed by Kairoi.* You can check the [Kairoi Runners documentation](https://github.com/emerick42/kairoi/blob/master/docs/runners.md) for the list of existing runners. Runners should be written to the Kairoi server only once during the deployment of the application, using the programmable interface provided by this library.
2. *Executables (in the application scope) responsible for handling job executions are implemented.* For example, in the case of a `Shell` runner, a CLI can be registered in your favorite framework, taking a job identifier as its main parameter, and executing the domain code associated with the received jobs. This part is outside of the scope of this library.
3. *Jobs are created on the fly by the application during its entire lifetime.* When needed during domain processes, the application can schedule jobs through this library. Kairoi will then automatically trigger the job execution at the proper time, launching the domain code associated with this job, following the Rules and Runners configured at the first step.

Usage
-----

[](#usage)

### Configuring a Client

[](#configuring-a-client)

The first thing you'll need to start communicating with a Kairoi server is a `Kairoi\Domain\Client\ClientInterface`. The library provides `Kairoi\Infrastructure\Client\Client`, as a default implementation of this interface. It takes as a parameter a `string` being the server URL (as accepted by the PHP method [stream\_socket\_client](https://www.php.net/manual/fr/function.stream-socket-client)), a `Kairoi\Domain\Client\Encoding\EncoderInterface` and a `Kairoi\Domain\Client\Decoding\DecoderInterface`, responsible for respectively encoding `Kairoi\Domain\Protocol\Request`s to a streamable message to send to the server, and decoding streamed messages received from the server to `Kairoi\Domain\Protocol\Response`. Once again, this library provides a `Kairoi\Domain\Client\Encoding\Encoder` to pass as the first parameter, and a `Kairoi\Infrastructure\Client\Decoding\ParsicaDecoder` for the second.

To summarize, you can create a client, configured to communicate with a Kairoi server listening on `127.0.0.1:5678`, with the following code:

```
