robsonalvesbh/semaphoro 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

robsonalvesbh/semaphoro

Composer 安装命令:

composer require robsonalvesbh/semaphoro

包简介

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

README 文档

README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

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

Set a storage

Parameters
  • Predis/Client $redisClient - required
  • String $prefix - optional (default value: semaphoro)

prefix is a namespace for redis.

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

Set a handler

Parameters
  • 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

Parameters
  • HandlerInterface $handler - required
$semaphoro = new Semaphoro($handler);
Methods
getAvailableProcess()

Get the next range available

$semaphoro->getAvailableProcess();
return
  • ProcessInterface
setUnprocessed()

Set unprocessed status when occurring an error

Parameters
  • ProcessInterface $process - required
$semaphoro->setUnprocessed($process);
return
  • void
remove()

Remove process from semaphoro when the process is finished

Parameters
  • ProcessInterface $process - required
$semaphoro->remove($process);
return
  • void

Code example

<?php
require_once 'vendor/autoload.php';

use Predis\Client;
use Semaphoro\Handlers\RangeHandler;
use Semaphoro\Semaphoro;
use Semaphoro\Storages\Redis;

$redis = new Redis(new Client([
    'scheme' => 'tcp',
    'host' => 'redis',
    'port' => 6379,
]));
$rangeHandler = new RangeHandler($redis);
$semaphoro = new Semaphoro($rangeHandler);
$process = $semaphoro->getAvailableProcess();

try {
    /**
     * YOUR CODE HERE
     */

    $semaphoro->remove($process);
} catch (Throwable $e) {
    $semaphoro->setUnprocessed($process);
}

Credits

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-01-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固