update README

This commit is contained in:
crazywhalecc 2023-03-19 14:05:30 +08:00
parent e4b37b9f9a
commit e7c1345dcb
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
2 changed files with 95 additions and 1 deletions

View File

@ -1,4 +1,5 @@
# static-php-cli
Compile A Statically Linked PHP With Swoole and other Extensions.
Compile a purely static PHP binary file with various extensions to make PHP-cli applications more portable!
@ -31,6 +32,8 @@ After stable release for this project, a single phar and single binary for this
And currently you may need to clone this branch and edit GitHub Action to build.
### Compilation
```bash
chmod +x spc
# fetch all libraries
@ -39,6 +42,38 @@ chmod +x spc
./spc build "bcmath,openssl,swoole" --build-all
```
### php-cli Usage
When using the parameter `--build-all` or not adding the `--build-micro` parameter,
the final compilation result will output a binary file named `./php`,
which can be distributed and used directly.
This file will be located in the directory `source/php-src/sapi/cli/`, simply copy it out for use.
```bash
./php -v
./php -m
./php your_code.php
```
### micro.sfx Usage
When using the parameter `--build-all` or `--build-micro`,
the final compilation result will output a file named `./micro.sfx`,
which needs to be used with your PHP source code like `code.php`.
This file will be located in the directory `source/php-src/sapi/micro/`, simply copy it out for use.
Prepare your project source code, which can be a single PHP file or a Phar file, for use.
```bash
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
cat micro.sfx code.php > single-app && chmod +x single-app
./single-app
# If packing a PHAR file, simply replace code.php with the Phar file path.
```
> In some cases, PHAR files may not run in a micro environment.
## Current Status
- [X] Basic CLI framework (by symfony/console)
@ -52,7 +87,24 @@ chmod +x spc
[Support Extension List](/ext-support.md)
## Open-Source LICENSE
## Contribution
Currently, there are only a few supported extensions.
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.
The basic principles for contributing are as follows:
- This project uses php-cs-fixer and phpstan as code formatting tools. Before contributing, please run `composer analyze` and `composer cs-fix` on the updated code.
- If other open source libraries are involved, the corresponding licenses should be provided.
Also, configuration files should be sorted using the command `sort-config` after modification.
For more information about sorting commands, see the documentation.
- Naming conventions should be followed, such as using the extension name registered in PHP for the extension name itself,
and external library names should follow the project's own naming conventions. For internal logic functions, class names, variables, etc.,
camelCase and underscore formats should be followed, and mixing within the same module is prohibited.
- When compiling external libraries and creating patches, compatibility with different operating systems should be considered.
## Open-Source License
This project is based on the tradition of using the MIT License for old versions,
while the new version references source code from some other projects.

View File

@ -1,4 +1,5 @@
# static-php-cli
Compile A Statically Linked PHP With Swoole and other Extensions. [English README](README-en.md)
编译纯静态的 PHP Binary 二进制文件,带有各种扩展,让 PHP-cli 应用变得更便携!
@ -34,6 +35,8 @@ Compile A Statically Linked PHP With Swoole and other Extensions. [English READM
未来会提供一个直接可使用的 phar 包和一个 phpmicro 打包的二进制文件,你可以直接从 Release 中获取并使用:
### 编译
```bash
chmod +x spc
# 拉取所有依赖库
@ -42,6 +45,34 @@ chmod +x spc
./spc build "bcmath,openssl,swoole" --build-all
```
### 使用 php-cli
采用参数 `--build-all` 或不添加 `--build-micro` 参数时,最后编译结果会输出一个 `./php` 的二进制文件,此文件可分发、可直接使用。
该文件编译后会存放在 `source/php-src/sapi/cli/` 目录中,拷贝出来即可。
```bash
./php -v
./php -m
./php your_code.php
```
### 使用 micro.sfx
采用项目参数 `--build-all``--build-micro` 时,最后编译结果会输出一个 `./micro.sfx` 的文件,此文件需要配合你的 PHP 源码使用。
该文件编译后会存放在 `source/php-src/sapi/micro/` 目录中,拷贝出来即可。
使用时应准备好你的项目源码文件,可以是单个 PHP 文件,也可以是 Phar 文件。
```bash
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
cat micro.sfx code.php > single-app && chmod +x single-app
./single-app
# 如果打包 PHAR 文件,仅需把 code.php 更换为 phar 文件路径即可
```
> 有些情况下的 phar 文件可能无法在 micro 环境下运行。
## 项目支持情况WIP
- [X] 基础结构编写(采用 symfony/console`
@ -55,6 +86,17 @@ chmod +x spc
[扩展支持列表](/ext-support.md)
## 贡献
目前支持的扩展较少,如果缺少你需要的扩展,可发起 Issue。如果你对本项目较熟悉也欢迎为本项目发起 Pull Request。
贡献基本原则如下:
- 项目采用了 php-cs-fixer、phpstan 作为代码规范工具,贡献前请对更新的代码执行 `composer analyze``composer cs-fix`
- 涉及到其他开源库的部分应提供对应库的协议,同时对配置文件在修改后采用命令 `sort-config` 排序。有关排序的命令,见文档。
- 应遵循命名规范,例如扩展名称应采取 PHP 内注册的扩展名本身,外部库名应遵循项目本身的名称,内部逻辑的函数、类名、变量等应遵循驼峰、下划线等格式,禁止同一模块混用。
- 涉及编译外部库的命令和 Patch 时应注意兼容不同操作系统。
## 开源协议
本项目依据旧版本惯例采用 MIT License 开源,新版本采用了部分项目的源代码做参考,特别感谢: