m2-oh/module-cloudflare
Composer 安装命令:
composer require m2-oh/module-cloudflare
包简介
Magento 2 module that integrates Cloudflare cache purging and real-IP resolution.
README 文档
README
A lightweight Magento 2 module that:
- Purges Cloudflare cache automatically whenever Magento's cache is flushed (admin panel or CLI).
- Resolves real visitor IPs by reading the
CF-Connecting-IPheader that Cloudflare injects, so Magento logs, rate-limiters, and geo-IP lookups see the actual client address instead of a Cloudflare proxy IP.
Requirements
| Dependency | Version |
|---|---|
| PHP | ≥ 8.1 |
| Magento | 2.4.x |
| m2-oh/module-core | * |
Installation
composer require m2-oh/module-cloudflare bin/magento module:enable OH_Cloudflare bin/magento setup:upgrade bin/magento cache:flush
Configuration
Navigate to Stores → Configuration → OH Core → Cloudflare.
| Field | Description |
|---|---|
| Enable Cache Purge | Master switch. When disabled, no API calls are made. |
| Account Email | The email address associated with your Cloudflare account. |
| Global API Key | Your Cloudflare Global API Key. Stored encrypted. |
| Zones to Purge | Multi-select of zones fetched live from the Cloudflare API. |
Tip: Save your email and API key first, then reload the page — the Zones field will populate automatically.
How It Works
Cache Purge
The module listens to three Magento cache events:
| Event | Trigger |
|---|---|
adminhtml_cache_flush_system |
Admin → Cache Management → Flush Magento Cache |
adminhtml_cache_flush_all |
Admin → Cache Management → Flush Cache Storage |
clean_media_cache_after |
Admin → Flush Media Storage |
When any of these events fires and the module is fully configured, Client::purgeAll() calls cachePurgeEverything for each configured zone via API. A success or per-zone failure message is displayed in the admin.
Real IP Resolution
A plugin on Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::getRemoteAddress() replaces the result with $_SERVER['HTTP_CF_CONNECTING_IP'] when present. This is a standard Cloudflare header that is always set when traffic passes through their proxy.
m2-oh/module-cloudflare 适用场景与选型建议
m2-oh/module-cloudflare 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 298 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 m2-oh/module-cloudflare 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 m2-oh/module-cloudflare 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 298
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2023-05-11