jobverplanke/craftcms-components
Composer 安装命令:
composer require jobverplanke/craftcms-components
包简介
Simple driver setup for CraftCMS components queue, cache or session
README 文档
README
Simple driver setup for CraftCMS components queue, cache or session for CraftCMS v4 and v5.
Available components and drivers
| Redis | Database | |
|---|---|---|
| Cache | ✅ | ✅ |
| Queue | ✅ | ❌ (default driver) |
| Session | ✅ | ✅ |
Note
Craft's default queue driver is the database. Do not configure the queue component in the app.php if you want to make use of the database queue driver.
Craft v4: https://craftcms.com/docs/4.x/config/app.html#queue
Craft v5: https://craftcms.com/docs/5.x/reference/config/app.html#queue
Installation
composer require jobverplanke/craftcms-components
Make sure that the yiisoft/yii2-redis package is installed when utilizing Redis
composer require yiisoft/yii2-redis
Configuration
To make use of a different driver per component is a breeze. Just specify the desired driver for the component you want to use in the components config array in either config/app.php or config/app.web.php (session only).
Database configuration
In order to use the database driver, configure CraftCMS as followed
Cache component
// .env CRAFT_CACHE_DRIVER=database // config/app.php use craft\helpers\App; use Verplanke\CraftComponents\Components\Cache; return [ 'components' => [ 'cache' => fn () => Cache::driver(App::env('CRAFT_CACHE_DRIVER')), ], ];
Queue component
// .env CRAFT_QUEUE_DRIVER=database // config/app.php use craft\helpers\App; use Verplanke\CraftComponents\Components\Queue; return [ 'components' => [ 'queue' => Queue::driver(App::env('CRAFT_QUEUE_DRIVER')), ], ];
Session component
// .env CRAFT_SESSION_DRIVER=database // config/app.web.php use craft\helpers\App; use Verplanke\CraftComponents\Components\Session; return [ 'components' => [ 'session' => fn () => Session::driver(App::env('CRAFT_SESSION_DRIVER')), ], ];
Redis configuration
If you want to use the Redis driver for a specific component, make sure Redis is configured
- Add the Redis component to the
app.php, see example below - Enable Redis by adding the following environment variables
REDIS_URL=ORREDIS_HOST,REDIS_PORTandREDIS_PASSWORD
Note
REDIS_URL takes precedence over REDIS_HOST, REDIS_PORT and REDIS_PASSWORD.
// config/app.php use Verplanke\CraftComponents\Components\Redis; return [ 'components' => [ 'redis' => Redis::connect(), ], ];
Cache component
// .env CRAFT_CACHE_DRIVER=redis // config/app.php use craft\helpers\App; use Verplanke\CraftComponents\Components\Cache; return [ 'components' => [ 'cache' => fn () => Cache::driver(App::env('CRAFT_CACHE_DRIVER')), ], ];
Queue component
// .env CRAFT_QUEUE_DRIVER=redis // config/app.php use craft\helpers\App; use Verplanke\CraftComponents\Components\Queue; return [ 'components' => [ 'queue' => Queue::driver(App::env('CRAFT_QUEUE_DRIVER')), ], ];
Session component
// .env CRAFT_SESSION_DRIVER=redis // config/app.web.php use craft\helpers\App; use Verplanke\CraftComponents\Components\Session; return [ 'components' => [ 'session' => fn () => Session::driver(App::env('CRAFT_SESSION_DRIVER')), ], ];
Environment Variable Configuration
The following environment variables are available for further configuration of the components
It's recommended to leave the following set to false when using Heroku. Heroku issue and Github issue
REDIS_SSLREDIS_SSL_VERIFY_PEERREDIS_SSL_VERIFY_PEER_NAME
| Required | Type | Default Value | Description / Remark | |
|---|---|---|---|---|
CRAFT_CACHE_DRIVER |
✅ | string | Possible values redis or database |
|
CRAFT_SESSION_DRIVER |
✅ | string | Possible values redis or database |
|
CRAFT_QUEUE_DRIVER |
✅ | string | Possible values redis or database |
|
REDIS_URL |
✅ | string | Takes precedence over REDIS_HOST, REDIS_PORT and REDIS_PASSWORD. |
|
REDIS_HOST |
string | Only when REDIS_URL is not used |
||
REDIS_PORT |
string | 6379 | Only when REDIS_URL is not used |
|
REDIS_PASSWORD |
string | Only when REDIS_URL is not used |
||
REDIS_DB |
integer | 0 | Default database to use, this database will be used for all Redis connections | |
REDIS_RETRIES |
integer | 1 | Th..ount of times to retry connecting after connection has timed out | |
REDIS_SSL |
boolean | false | Use SSL connection when connecting with Redis. Recommended to use false when using Heroku |
|
REDIS_SSL_VERIFY_PEER |
boolean | false | Verify peer SSL certificate. Recommended to use false when using Heroku |
|
REDIS_SSL_VERIFY_PEER_NAME |
boolean | false | Verify peer name of SSL certificate. Recommended to use false when using Heroku |
|
REDIS_CACHE_DB |
integer | 1 | Which database to use for the cache database. Make sure the cache database is separated from the queue and session database | |
REDIS_QUEUE_DB |
integer | 3 | Which database to use for the queue database | |
REDIS_QUEUE_CHANNEL |
string | queue | Queue channel to use | |
REDIS_QUEUE_TTR |
integer | 300 | Max time for job execution, unit in seconds | |
REDIS_QUEUE_ATTEMPTS |
integer | 3 | Max number of attempts | |
REDIS_SESSION_DB |
integer | 1 | Which database to use for the session database. |
jobverplanke/craftcms-components 适用场景与选型建议
jobverplanke/craftcms-components 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 381 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jobverplanke/craftcms-components 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jobverplanke/craftcms-components 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 381
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-18