alialican/hubspot-rate-limiter
Composer 安装命令:
composer require alialican/hubspot-rate-limiter
包简介
This package wraps default hubspot/api-client package with a rate limiter, so that you dont breach API limits
README 文档
README
This package provides a rate limiting wrapper for the HubSpot API client, allowing you to set per-second and daily rate limits for your HubSpot API calls. It leverages the Redis cache store for efficient rate limiting. If Redis is not available, it falls back to a generic cache implementation.
Installation
Install the package using Composer:
composer require alialican/hubspot-rate-limiter
Usage:
1.Import the package in your code:
use HubSpotRateLimiter\HubSpotClientWrapper;
2.Create an instance of the HubspotClientWrapper class and pass in the required dependencies:
use Illuminate\Support\Facades\Cache;
use HubSpot\Discovery\Discovery;
$hubspotClient = new Discovery();
$secondLimit = 100; // Replace with your desired per-second limit
$dailyLimit = 250000; // Replace with your desired daily limit
$hubspot = new HubspotClientWrapper($hubspotClient, $secondLimit, $dailyLimit);
Use the $hubspot instance as you would use the original HubSpot API client. The rate limiter will automatically enforce the specified rate limits on each API call.
$result = $hubspot->crm()->contacts()->getAll();
Important Points
This package uses Laravel's Cache facade for rate limiting. Make sure you have the proper cache driver set up in your Laravel configuration. When the cache driver is Redis, the rate limiter directly interacts with Redis for efficient rate limiting. Ensure that your Redis configuration is correctly set up. If your Redis setup is unusual or complex, the Redis-based rate limiting may not work as expected. The rate limiting mechanism used in the enforceRateLimitGeneric method is simplistic and may not handle high rates of concurrency as efficiently as the Redis-based solution. The package assumes that the Redis server supports the eval command, as it uses Lua scripts for rate limiting. If your Redis server does not support this command, the rate limiting may fail. Please test the package thoroughly in your specific environment to ensure it meets your requirements and works correctly with your Redis configuration.
License This package is open-source and licensed under the MIT License.
Feel free to customize and expand on the README to provide more information or clarify any additional details specific to your use case.
alialican/hubspot-rate-limiter 适用场景与选型建议
alialican/hubspot-rate-limiter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alialican/hubspot-rate-limiter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alialican/hubspot-rate-limiter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-10