chemaclass/shared-state
Composer 安装命令:
composer require chemaclass/shared-state
包简介
A library to share state between different processes.
README 文档
README
Goal
Sharing state between different processes in PHP.
Installation
composer require chemaclass/shared-state
Motivation
This experiment is motivated by the idea of sharing states between different processes that need to be aware of some data in common. At first sight, you might think a regular DB would be suitable for this, like MySQL, PostgreSQL, or even Mongo or Redis... but the idea here is to avoid the complexity of an external DB system and keep it simple. Keep it in a file.
Because they are different processes, there is no simple way to share the state between the processes themselves (that doesn't involve storing the data somewhere else), so we have to rely on PHP extensions or save the data on the persistent disk.
The main idea behind this library is to create a temporal file that will save the state you want to share between the different processes on runtime. And once all the processes consumed that data, it would be safe to remove that file.
That means that the goal is to be able to share a temporal state between processes.
Example
You can check the example in example/main.php:
cd example
php main.php
Config
This file is optional because each state you want to share is referenced and unique by its id (any raw string). Still, suppose you want to define a custom file name (where to store that temporal value), or define the "minutes difference limit" between the new and old stored record. In that case, you can customize the default behavior of the library.
Create at the root of your project a file named shared-states.php where you can define different configurations for different shared states of your application. For example:
<?php return [ 'id-bool' => [ 'file-name' => 'shared-boolean-state.json', 'minutes-diff-limit' => 1, ], 'id-string' => [ 'file-name' => 'shared-string-state.json', ], // ... ];
These are optional settings. The file-name will be generated using the id of the shared-state (aka the key
id-boolorid-stringin this example). But you can use any id you like. It doesn't need to be present in this configuration list.
chemaclass/shared-state 适用场景与选型建议
chemaclass/shared-state 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「state」 「share」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chemaclass/shared-state 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chemaclass/shared-state 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chemaclass/shared-state 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
A simple state dropdown field for SilverStripe forms
Improves silverstripes html meta data options.
A state Machine library for business processes
Metamel Addresses is a polymorphic Laravel package, for address book management. You can add addresses to any eloquent model with ease.
Convert and operate with FIPS codes for states, counties, etc.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-30