PHPackages                             robsonalvesbh/semaphoro - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. robsonalvesbh/semaphoro

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

robsonalvesbh/semaphoro
=======================

This library will help you to run multiple process with PHP.

v1.0.1(7y ago)16PHP

Since Jan 29Pushed 7y agoCompare

[ Source](https://github.com/robsonalvesbh/semaphoro)[ Packagist](https://packagist.org/packages/robsonalvesbh/semaphoro)[ Docs](https://github.com/robsonalvesbh/semaphoro)[ RSS](/packages/robsonalvesbh-semaphoro/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0fdbb0f05323bddd37f6c495aeedd34317047abc37756987f461c54e1d4c916c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726f62736f6e616c76657362682f53656d6170686f726f2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/robsonalvesbh/Semaphoro/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/fbb31fbf3326e174681fea6eeec92a2b05fda03dd6fbb15e70612a0c0694f65e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726f62736f6e616c76657362682f53656d6170686f726f2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/robsonalvesbh/Semaphoro/?branch=master)[![Build Status](https://camo.githubusercontent.com/9158c98b128a75dcea738c1e4dd9bb275f9a1c8da65fcba67dfa745c311c03e0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726f62736f6e616c76657362682f53656d6170686f726f2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/robsonalvesbh/Semaphoro/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/4245278d3acbf4edd5af92c0eaaf2fb8151bcc231621931d4d392f667e591fd8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726f62736f6e616c76657362682f53656d6170686f726f2f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

Semaphoro
=========

[](#semaphoro)

This library will help you to run multiple process with PHP.

Semaphoro library performs the orchestration of the processes avoiding that two or more workers that are running in parallel run the same processes, avoiding duplication of processes and still have a contingency to process again in case some process fails.

### How to use

[](#how-to-use)

#### Set a storage

[](#set-a-storage)

###### Parameters

[](#parameters)

- **[Predis/Client](https://packagist.org/packages/predis/predis)** $redisClient - *required*
- **String** $prefix - *optional* (default value: semaphoro)

*prefix* is a namespace for redis.

```
$redis = new Redis($redisClient, $prefix);
```

#### Set a handler

[](#set-a-handler)

###### Parameters

[](#parameters-1)

- **StorageInterface** $storage - *required*
- **int** $rangeLength - *optional* (default value: 50)

*rangeLength* is the quantity of process in a range

```
$rangeHandler = new RangeHandler($storage, $rangeLength);
```

The RangeHandler is projected to work with incremental numbers like ID

#### Get semaphoro

[](#get-semaphoro)

###### Parameters

[](#parameters-2)

- **HandlerInterface** $handler - *required*

```
$semaphoro = new Semaphoro($handler);
```

###### Methods

[](#methods)

##### getAvailableProcess()

[](#getavailableprocess)

Get the next range available

```
$semaphoro->getAvailableProcess();
```

###### return

[](#return)

- ProcessInterface

##### setUnprocessed()

[](#setunprocessed)

Set unprocessed status when occurring an error

###### Parameters

[](#parameters-3)

- **ProcessInterface** $process - *required*

```
$semaphoro->setUnprocessed($process);
```

###### return

[](#return-1)

- void

##### remove()

[](#remove)

Remove process from semaphoro when the process is finished

###### Parameters

[](#parameters-4)

- **ProcessInterface** $process - *required*

```
$semaphoro->remove($process);
```

###### return

[](#return-2)

- void

### Code example

[](#code-example)

```
