update README.md

This commit is contained in:
crazywhalecc 2022-05-16 17:02:57 +08:00
parent 2b802c710f
commit fbf4016965
2 changed files with 54 additions and 2 deletions

View File

@ -3,15 +3,17 @@ Compile A Statically Linked PHP With Swoole and other Extensions.
BTW, It's only for CLI mode.
[![version](https://img.shields.io/badge/version-1.4.3-green.svg)]()
[![version](https://img.shields.io/badge/version-1.5.0-green.svg)]()
![Build Actions](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build-php.yml/badge.svg)
## Compilation Requirements
- Supporting architecture: `x86_64`, `arm64(aarch64)`, `armv7(armv7l)`
- Docker required (or alpine linux 3.13+)
- Supporting PHP version from 7.2 to 8.1
## Running Requirements
Linux
## Usage
@ -28,6 +30,24 @@ But this script has some Chinese comments and prompts, if you cannot understand
bash -c "`curl -fsSL https://raw.githubusercontent.com/crazywhalecc/static-php-cli/master/install-runtime.sh`"
```
## Packing PHP Code into a Static Binary
From v1.5.0, we support packing PHP code into a static binary. You can pack your PHP code into a static binary by micro.
You can directly download `micro-` prefix file, untar it and you will get file `micro.sfx`.
Here's a simple example to use it:
```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 phar into a static binary, just change code.php to your phar path.
```
> Thanks <https://github.com/dixyes/phpmicro>
## Compiling
Here's help command to compile it yourself:
@ -124,8 +144,14 @@ To customize PHP extensions, edit `docker/extensions.txt` file, and rules below:
## Running preview
### Using static binary
<img width="881" alt="未命名" src="https://user-images.githubusercontent.com/20330940/168441751-e62cb8d4-a3c8-42d9-b34e-d804b39756a1.png">
### Using swoole application packed with micro
## References
- <https://blog.terrywh.net/post/2019/php-static-openssl/>
- <https://stackoverflow.com/a/37245653>

View File

@ -3,18 +3,22 @@ Compile A Statically Linked PHP With Swoole and other Extensions. [English READM
编译纯静态的 PHP Binary 二进制文件,带有各种扩展,让 PHP-cli 应用变得更便携!
同时可以使用 micro 二进制文件,将 PHP 源码和 PHP 二进制构建为一个文件分发!
注:只能编译 CLI 模式,暂不支持 CGI 和 FPM 模式
[![版本](https://img.shields.io/badge/script--version-1.4.3-green.svg)]()
[![版本](https://img.shields.io/badge/script--version-1.5.0-green.svg)]()
[![License](https://img.shields.io/badge/License-MIT-blue.svg)]()
![Build Actions](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build-php.yml/badge.svg)
## 编译环境需求
- 目前支持 arm64、x86_64、armv7l 架构
- 需要 Docker也可以直接在 Alpine Linux 上使用)
- 脚本支持编译的 PHP 版本7.2 ~ 8.1
## 运行环境需求
Linux
## 直接使用
@ -30,6 +34,22 @@ Linux
bash <(curl -fsSL https://dl.zhamao.xin/php-bin/install-runtime.sh)
```
## PHP 代码打包使用
v1.5.0 脚本开始,脚本新增了对 PHP 代码打包的支持,可以将 PHP 代码打包为一个文件分发,方便在 Linux 系统使用。(仅支持 PHP >= 8.0
1. 可以直接在上面的下载链接中下载 `micro-` 开头的文件并解压,获得 `micro.sfx` 文件后,使用以下命令和 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 文件路径即可
```
> 感谢 <https://github.com/dixyes/phpmicro> 项目提供的支持
## 自行编译
可以自己使用 Dockerfile 进行编译构建:
@ -132,8 +152,14 @@ export VER_PHP="8.1.6"
## 运行示例
### 静态 PHP 运行脚本
<img width="881" alt="未命名" src="https://user-images.githubusercontent.com/20330940/168441751-e62cb8d4-a3c8-42d9-b34e-d804b39756a1.png">
### micro 打包运行 Swoole
## 原理
静态编译是一项比较多见于 Golang 的编译方式,在传统的 Linux 系统下正常的程序和库基本是动态编译链接Dynamically linked也就是说不同程序引用同样的库可以共用减少资源重复。