承接 aportela/simple-throttle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

aportela/simple-throttle

最新稳定版本:1.0.3

Composer 安装命令:

composer require aportela/simple-throttle

包简介

Custom php throttle system

README 文档

README

This is a simple approach to implement exponential backoff for retrying operations that may fail intermittently, such as network requests (API calls?) or file access. While there are more robust and optimized solutions out there, this is just a lightweight strategy I use in some of my personal projects when I need to handle temporary failures without overcomplicating things. It’s not meant for production-grade systems, just a basic solution for my use cases.

Requirements

  • mininum php version 8.4

Install (composer) dependencies:

composer require aportela/simple-throttle

Code example:

<?php

    require "vendor/autoload.php";

    $logger = new \Psr\Log\NullLogger("");

    $throttle = new \aportela\SimpleThrottle\Throttle($logger, 500, 5000);

    for ($i = 0; $i < 32; $i++) {
        // throttle default time between iterations
        $throttle->throttle();
        // instead of this dummy code block, could you make a call to a remote API here that could fail due to a rate limit
        $failed = (bool) mt_rand(0, 1);
        if (! $failed) {
            echo "Success... reseting throttle to default" . PHP_EOL;
            // on interation success reset throttle to default time
            $throttle->reset();
        } else {
            echo "Error... incrementing throttle" . PHP_EOL;
            // on interation error increment throttle ( ms = ms + 500 ms)
            $throttle->increment(\aportela\SimpleThrottle\ThrottleDelayIncrementType::INCREMENT_500_MILLISECONDS);
        }
    }

PHP Composer

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: AGPL-3.0-only
  • 更新时间: 2025-11-01