sokil/php-bitmap
Composer 安装命令:
composer require sokil/php-bitmap
包简介
Bitmap representation with bitwise operations
关键字:
README 文档
README
Bitmap, also called bit array is a data structure that compactly store set of values as bits of integer. More data can be read at http://en.wikipedia.org/wiki/Bit_array.
It is useful when required compact way to represent combination of values and simple manipulations with them. One byte can represent eight independent values.
Installation
composer require sokil/php-bitmap
Useage
Lets see example. Errors in PHP represents as constants:
E_ERROR = 1 (0);
E_WARNING = 2 (1);
E_PARSE = 4 (2);
E_NOTICE = 8 (3);
E_CORE_ERROR = 16 (4);
E_CORE_WARNING = 32 (5);
E_COMPILE_ERROR = 64 (6);
E_COMPILE_WARNING = 128 (7);
E_USER_ERROR = 256 (8);
E_USER_WARNING = 512 (9);
E_USER_NOTICE = 1024 (10);
E_STRICT = 2048 (11);
E_RECOVERABLE_ERROR = 4096 (12);
E_DEPRECATED = 8192 (13);
E_USER_DEPRECATED = 16384 (14);
E_ALL = 32767 (15);
Every error level represent logical "1", and combination of all this values may be represent only by two bytes. E_ERROR represent first bit of byte, E_WARNING - second, etc.
Combination of E_WARNING and E_NOTICE in binary system is "1010" or 10 in decimal system.
Class that represents bitmap of PHP errors:
class PhpError extends \Sokil\Bitmap { /** * Show errors * Set first bit, which represents E_ERROR, to "1" */ public function showErrors() { $this->setBit(0); return $this; } /** * Hide errors * Set first bit, which represents E_ERROR, to "0" */ public function hideErrors() { $this->unsetBit(0); return $this; } /** * Check if errors shown * Check if first bit set to 1 */ public function isErrorsShown() { return $this->isBitSet(0); } /** * Show warnings * Set second bit, which represents E_WARNING, to "1" */ public function showWarnings() { $this->setBit(1); return $this; } /** * Hide warnings * Set second bit, which represents E_WARNING, to "0" */ public function hideWarnings() { $this->unsetBit(1); return $this; } /** * Check if warnings shown * Check if second bit set to 1 */ public function isWarningsShown() { return $this->isBitSet(1); } }
Now we can easely manipulate with errors:
// load current error levels $error = new PhpError(error_reporting()); // enable errors and warnings $error->showErrors()->showWarnings(); // set error reporting error_reporting($error->toInt()); // check if warnings shown var_dump($error->isWarningsShown()); // value may be set by mask // E_USER_ERROR | E_USER_WARNING is 256 + 512; $error->setBitsByMask(E_USER_ERROR | E_USER_WARNING);
sokil/php-bitmap 适用场景与选型建议
sokil/php-bitmap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.07k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2014 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bitmap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sokil/php-bitmap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sokil/php-bitmap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sokil/php-bitmap 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
BMP image support for PHP's GD
Bitmask compatible with JavaScript big-bit-mask - the bitmask serializable into a base64-like, url-safe string.
Bitmap tools
A Simple Bloom Filter for PHP
Bitmap for PHP
Bitmap data mapper bundle for Symfony
统计信息
- 总下载量: 4.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-20