green-elephpant/carbon-aware
Composer 安装命令:
composer require green-elephpant/carbon-aware
包简介
SDK to help your applications reduce carbon emissions
README 文档
README
Green ElePHPant - CarbonAware
The Green ElePHPant wants to help you to reduce the carbon emissions of your software.
One way of doing so is to utilize energy when it is the "greenest" - i.e., when it most of it comes from renewable energies rather burning fossil fuels.
GreenElephpant\CarbonAware is a simple wrapper for APIs that provide information about the current or future carbon
intensity at many regions worldwide. Currently, we support CO2Signal and
Electricity Maps. Hopefully more to come!
Key concept
Building carbon aware applications means that certain activities or jobs will not, or at least in lower frequency, be carried out if the carbon intensity is too high.
For example, if the carbon intensity is low, we can update a dashboard more often than if it is not:
if ($carbonAwareService->isLow()) { $schedule ->command('dashboard:update') ->everyFiveMinutes(); } else { $schedule ->command('dashboard:update') ->everyTenMinutes(); }
Installation
Simply use composer to add GreenElephpant\CarbonAware to your project:
composer require green-elephpant/carbon-aware
Configuration
GreenElephpant\CarbonAware was designed to require as few external dependencies as possible so that it can fit in
almost every project. It uses several PSR for e.g. HTTP messages (PSR-17) and clients (PSR-18), so it won't work out
of the box but require a bit (but not a lot) of hand wiring.
use Buzz\Client\Curl; use GreenElephpant\CarbonAware\DataProvider\EnergyCharts\Connector\EnergyChartsConnector; use GreenElephpant\CarbonAware\DataProvider\EnergyCharts\EnergyCharts; use GreenElephpant\CarbonAware\Service\CarbonAwareService; use Nyholm\Psr7\Factory\Psr17Factory; // Create HTTP client with HTTP message factory // E.g. nyholm/psr7 and kriswallsmith/buzz $psr17Factory = new Psr17Factory(); $psr18Client = new Curl($psr17Factory); // Create Connector (here: for energy-charts.info) $energyChartsConnector = new EnergyChartsConnector( $psr18Client, $psr17Factory, ); // Setup location (the region of the world you want to get the information for) $location = new GreenElephpant\CarbonAware\Location\Location('DE'); // Finally create the DataProvider instance, using the connector and the location $dataProvider = new EnergyCharts( $co2SignalConnector, $location ); $carbonAwareService = new CarbonAwareService($connector
Internals
GreenElephpant\CarbonAware uses 3rd party APIs to receive carbon intensity data. To ensure future-proof and easy
maintenance,
Connector: the actual API wrapper. Provides easy access to the relevant API endpoints (note: only those endpoints that are relevant for this project are supported.DataProvider: the link betweenCarbonAwareService: provides uniform API
green-elephpant/carbon-aware 适用场景与选型建议
green-elephpant/carbon-aware 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 green-elephpant/carbon-aware 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 green-elephpant/carbon-aware 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-19