定制 crazywhalecc/static-php-cli 二次开发

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

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

crazywhalecc/static-php-cli

Composer 安装命令:

composer require crazywhalecc/static-php-cli

包简介

Build single static PHP binary, with PHP project together, with popular extensions included.

README 文档

README

Chinese readme English readme Releases CI License Discord

StaticPHP is a powerful tool designed for building portable executables including PHP, extensions, and more.

Important

We are preparing to release v3, which will include a project rename from static-php-cli to StaticPHP. And this branch is for v3. For v2, please check the v2 branch. Please update your references and stay tuned for the official release.

Features

  • 🐘 Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5
  • 👜 Build single-file PHP executable with zero dependencies
  • 🍔 Build phpmicro self-extracting executables (combines PHP binary and source code into one file)
  • 💊 Automatic build environment checker with auto-fix capabilities
  • Linux, macOS, Windows support
  • 🔧 Easy to extend with vendor mode and custom registries
  • 📚 Intelligent dependency management
  • 📦 Self-contained spc executable for easy self-installation
  • 🔥 Support 100+ popular PHP extensions
  • 💾 UPX compression support (reduces binary size by 30-50%)

Single-file standalone php-cli:

out1

Combine PHP code with PHP interpreter using phpmicro:

out2

Quickstart

1. Download spc binary

# For Linux x86_64
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64
# For Linux aarch64
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64
# macOS x86_64 (Intel)
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64
# macOS aarch64 (Apple)
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-aarch64
# Windows (x86_64, win10 build 17063 or later, please install VS2022 first)
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/v3/spc-bin/nightly/spc-windows-x64.exe

For macOS and Linux, add execute permission first:

chmod +x ./spc

2. Build Static PHP

First, create a craft.yml file and specify which extensions you want to include from extension list or command generator:

# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5
php-version: 8.5
# Put your extension list here
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
sapi:
  - cli
  - micro
download-options:
  parallel: 10

Run command:

./spc craft

# Output full console log
./spc craft -vvv

3. Static PHP usage

Now you can copy binaries built by StaticPHP to another machine and run with no dependencies:

# php-cli
buildroot/bin/php -v

# phpmicro
echo '<?php echo "Hello world!\n";' > a.php
./spc micro:combine a.php -O my-app
./my-app

Documentation

The current README contains basic usage. For the complete feature set of StaticPHP, see https://static-php.dev.

Direct Download

If you do not want to build yet or just want to test first, you can download example pre-compiled artifacts from Actions or from a self-hosted server.

We offer 2 types of extension sets for each PHP version:

  • gigantic: Includes as many extensions as possible, the binary size is about 100-150MB.
  • base: Only includes a few extensions used by StaticPHP itself, the binary size is about 10MB.

WIP

Build Online (using GitHub Actions)

When the direct-download binaries above cannot meet your needs, you can use GitHub Actions to easily build a statically compiled PHP while defining your own extension list.

  1. Fork this repository.
  2. Go to the Actions of the project and select CI.
  3. Select Run workflow, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. bcmath,curl,mbstring)
  4. After waiting for the workflow to finish, open the corresponding run and download Artifacts.

If you enable debug, all logs will be output at build time, including compiled logs, for troubleshooting.

We are also planning to provide a reusable GitHub Actions workflow in the future, so that you can easily build static PHP in your own repository, without forking this project.

Contribution

If the extension you need is missing, you can create an issue. If you are familiar with this project, you are also welcome to initiate a pull request.

If you want to contribute documentation, please just edit in docs/.

Sponsor this project

You can sponsor me or my project from GitHub Sponsor. A portion of your donation will be used to maintain the static-php.dev server.

Special thanks to sponsors below:

Beyond Code Logo

NativePHP Logo

Open-Source License

This project itself is licensed under MIT. Some newly added extensions and dependencies may originate from other projects. The headers of those source files may also include additional LICENSE and AUTHOR information.

Please use the bin/spc dump-license command to export the open source licenses used in the project after compilation, and comply with the corresponding project's LICENSE.

crazywhalecc/static-php-cli 适用场景与选型建议

crazywhalecc/static-php-cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.21k 次下载、GitHub Stars 达 1.9k, 最近一次更新时间为 2023 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 crazywhalecc/static-php-cli 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 17.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1897
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1897
  • Watchers: 20
  • Forks: 391
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-19