定制 awesome/crc_fast 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

awesome/crc_fast

Composer 安装命令:

pie install awesome/crc_fast

包简介

Fast SIMD hardware-accelerated CRC-32 and CRC-64 calculation capable of >100GiB/s

README 文档

README

Tests status Latest Stable Version

Fast, hardware-accelerated CRC calculation in PHP for all known CRC-32 and CRC-64 variants using SIMD intrinsics, which can exceed 100GiB/s for CRC-32, and 50GiB/s for CRC-64, on modern systems.

It is much, much faster (up to >200X) than the native crc32, crc32b, and crc32c implementations in PHP, plus adds many more variants (particularly CRC-64/NVME).

The performance gains are especially pronounced on aarch64 (Arm) systems, since PHP doesn't currently use hardware acceleration there.

CRC-64/NVME

CRC-64/NVME is in use in a variety of large-scale and mission-critical systems, software, and hardware, such as:

CRC-32/PHP, one of PHP's special flowers 🌼

hash('crc32') in PHP is not the same as crc32() in PHP, and doesn't match the crc32 definition or output in many other programming languages and implementations (which is typically CRC-32/ISO-HDLC)

Instead, it's actually CRC-32/BZIP2 which is then byte-reversed. This extension provides a CrcFast\CRC_32_PHP algorithm const that performs the same calculation, but accelerated.

$checksum = CrcFast\checksum(
    algorithm: CrcFast\CRC_32_PHP,
    string: '123456789'
); // 181989fc

Related SIMD-accelerated PHP extensions

  • simdutf PHP extension for Unicode validation and transcoding at billions of characters per second using the simdutf project.
  • simdjson_plus PHP extension for parsing gigabytes of JSON per second using the simdjson project.

Requirements

Uses the crc_fast Rust package and its C-compatible shared library under the hood, so you'll need to have built and installed it. (See Usage, below).

Changes

See the change log.

Installing

Use Composer to install this library using PIE (note the Requirements above):

composer install awesome/crc-fast

If you're using a non-standard installation location for the crc_fast library, you may need to specify where the crc_fast header (in include) and shared library (in lib) can be found:

composer install awesome/crc-fast --with-crc-fast=/path/to/crc-fast

Building

Like most PHP extensions, you can also build yourself:

phpize
./configure
make

or with a custom crc_fast location where the crc_fast header and shared library can be found:

phpize
./configure --with-crc-fast=/path/to/crc-fast
make

Usage

Examples are for CRC-64/NVME, but you can use any supported algorithm variant.

Calculate CRC-64/NVME checksums:

// calculate the checksum of a string
$checksum = CrcFast\hash(
    algorithm: CrcFast\CRC_64_NVME,
    string: '123456789'
); // ae8b14860a799888

// calculate the checksum of a file, which will chunk through the file optimally,
// limiting RAM usage and maximizing throughput
$checksum = CrcFast\hash_file(
    algorithm: CrcFast\CRC_64_NVME,
    filename: 'path/to/123456789.txt',
); // ae8b14860a799888

Calculate CRC-64/NVME checksums with a Digest for intermittent / streaming / etc workloads:

$crc64Digest = CrcFast\Digest::new(
    algorithm: CrcFast\CRC_64_NVME,
);

// write some data to the digest
$crc64Digest->write('1234');

// write some more data to the digest
$crc64Digest->write('56789');

// calculate the entire digest
$checksum = $crc64Digest->finalize(); // ae8b14860a799888

Get a list of supported algorithm variants

$algorithms = get_supported_algorithms();

var_dump($algorithms);

Equivalents to PHP functions

crc32()

Calculates CRC-32/ISO-HDLC as an integer.

$checksum = CrcFast\crc32(
    data: '123456789'
); // 3421780262

hash('crc32') 🌼

Calculates CRC-32/PHP as binary or hex.

$checksum = CrcFast\hash(
    algorithm: CrcFast\CRC_32_PHP,
    string: '123456789'
    binary: false,
); // 181989fc

hash('crc32b')

Calculates CRC-32/ISO-HDLC as binary or hex.

$checksum = CrcFast\hash(
    algorithm: CrcFast\CRC_32_ISO_HDLC,
    string: '123456789'
    binary: false,
); // cbf43926

hash('crc32c')

Calculates CRC-32/ISCSI as binary or hex.

$checksum = CrcFast\hash(
    algorithm: CrcFast\CRC_32_ISCSI,
    string: '123456789'
    binary: false,
); // b798b438

IDE Stubs

This extension comes with IDE stubs for use with your favorite development environment.

Tests

See the tests directory for test coverage, which also double as useful examples.

make test

Platform support

This extension has been extensively tested on macOS and Linux, on both aarch64 and x86_64.

At Awesome we use it in production at very large scale on Linux on both Flickr and SmugMug.

This extension is not currently supported on Windows. :(

The underlying crc_fast library (same authors) builds and works on Windows, so this is likely just a build issue with creating a working config.w32 implementation. (I took a quick stab, failed, and moved on since we don't use Windows in production.)

If you want to help, please open a working PR. I'd love to merge it.

Performance

PHP already uses SIMD intrinsics for CRC-32 calculations on x86_64 but not on aarch64. Even on x86_64, this library provides considerable improvements, in addition to supporting many more variants.

Tested using the maximum settings for crc_fast for each platform, using 1MiB random payloads.

CRC-32/ISCSI and CRC-32/ISO-HDLC

Arch Brand CPU System PHP crc_fast Speedup
x86_64 Intel Sapphire Rapids EC2 c7i.metal-48xl ~27.0 GiB/s ~108.1 GiB/s ~4X
x86_64 AMD Genoa EC2 c7a.metal-48xl ~13.6 GiB/s ~53.7 GiB/s ~4X
aarch64 AWS Graviton4 EC2 c8g.metal-48xl ~0.4 GiB/s ~52.3 GiB/s ~141X
aarch64 Apple M3 Ultra Mac Studio (32 core) ~0.4 GiB/s ~99.6 GiB/s ~233X

CRC-32/PHP 🌼

Arch Brand CPU System PHP crc_fast Speedup
x86_64 Intel Sapphire Rapids EC2 c7i.metal-48xl ~26.6 GiB/s ~27.4 GiB/s n/a
x86_64 AMD Genoa EC2 c7a.metal-48xl ~13.6 GiB/s ~25.4 GiB/s ~2X
aarch64 AWS Graviton4 EC2 c8g.metal-48xl ~0.4 GiB/s ~31.5 GiB/s ~73X
aarch64 Apple M3 Ultra Mac Studio (32 core) ~0.4 GiB/s ~57.8 GiB/s ~134X

CRC-64/NVME

Note that PHP has no native equivalent.

Arch Brand CPU System crc_fast
x86_64 Intel Sapphire Rapids EC2 c7i.metal-48xl ~54.6 GiB/s
x86_64 AMD Genoa EC2 c7a.metal-48xl ~27.0 GiB/s
aarch64 AWS Graviton4 EC2 c8g.metal-48xl ~37.0 GiB/s
aarch64 Apple M3 Ultra Mac Studio (32 core) ~70.0 GiB/s

License

cfc-fast is dual-licensed under

awesome/crc_fast 适用场景与选型建议

awesome/crc_fast 是一款 基于 C++ 开发的 Composer 扩展包,目前已累计 48 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「checksum」 「crc32」 「crc」 「crc64」 「simd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 awesome/crc_fast 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 awesome/crc_fast 我们能提供哪些服务?
定制开发 / 二次开发

基于 awesome/crc_fast 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 48
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: C++

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-04-11