Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swoole-cli 各分支功能区别 #273

Open
jingjingxyk opened this issue Jul 14, 2023 · 4 comments
Open

swoole-cli 各分支功能区别 #273

jingjingxyk opened this issue Jul 14, 2023 · 4 comments

Comments

@jingjingxyk
Copy link
Contributor

jingjingxyk commented Jul 14, 2023

swoole-cli 各分支功能区别

构建环境 alpine 3.18

支持的扩展列表

分支名称 与主分支的区别 PHP 版本 C 编译器
main 主分支是在 PHP源码基础之上裁剪、优化、添加新功能,详细介绍 8.1.27(固定) clang(固定)
experiment 在 main 分支基础上改进,新增功能特性 8.1.27(固定) clang(固定)
experiment_v4.8.x 在 experiment 分支基础上改进,
swoole版本固定为v4.8.x,
openssl版本为 V1,
curl库不启用 http2、http3支持
8.1.27(固定) clang(固定)
build_native_php
build-static-php
在 experiment 分支基础上改进,
用于构建原生的PHP版本,
可构建生成包含swow扩展的二进制文件 ,PHP源码未裁剪
8.2.4 (允许指定其它版本) clang(默认), gcc
php-fpm 在 build_native_php 分支基础上改进,
不包含swoole扩展 ,
启用PHP FastCGI
用于构建原生的PHP-FPM
8.2.4 (允许指定其它版本) clang(默认), gcc
build_native_php_sfx_micro 在 build_native_php 分支基础上改进,
只构建 phpmicro 版本
8.2.4 (允许指定其它版本) clang(默认), gcc
build_php_7.4 在 build_native_php 分支基础上改进,
swoole版本固定为v4.8.x,
openssl版本为 V1,
curl库不启用 http2、http3支持
7.4.33 (允许指定其它次版本) clang(默认), gcc
php-fpm-7.4 在 build_php_7.4 分支基础上改进,
不包含swoole 扩展
openssl版本为 V1,
curl库不启用 http2、http3支持
7.4.33 (允许指定其它次版本) clang(默认), gcc
build_php_7.3 在 build_php_7.4 分支基础上改进,
gd、zip、imagick扩展 未能启用 ,
swoole版本固定为v4.8.x,
openssl版本为 V1,
curl库不启用 http2、http3支持 ,
启用PHP FastCGI,
用于构建原生的PHP-FPM
7.3.33 (允许指定其它次版本) gcc(固定)
@jingjingxyk
Copy link
Contributor Author

jingjingxyk commented Jul 14, 2023

experiment 分支新增:

  1. 允许指定扩展下载地址
  2. 可以使用curl 、 git 等方式下载库或者扩展,
  3. 新增简易webui 辅助: https://swoole-cli-ui.jingjingxyk.com/
  4. 新增快速初始化PHP 运行环境脚本setup-php-runtime.sh
  5. 编译gd 扩展,扩展启用依赖 libavif 库,为了支持 avif 格式的图片,编译时添加 --with-libavif=1

build_native_php分支新增:

  1. 继承 experiment 分支功能
  2. 可指定 PHP 版本,例如: --with-php-version=8.2.11
  3. 可指定 C 编译器 为GCC,例如: --with-c-compiler=gcc
  4. 可指定 构建类型,用于新增扩展时,验证扩展启用参数,例如: --with-build-type=dev
  5. 可指定 http 代理,用于下载,扩展和依赖库 ,例如: --with-http-proxy=http://192.168.3.26:8015
  6. 可编译swow扩展的PHP可执行文件,例如: php prepare.php -swoole +swow
  7. 可在 debian 、ubuntu 容器环境中验证静态编译

@jingjingxyk
Copy link
Contributor Author

jingjingxyk commented Jul 14, 2023

PHP 静态编译 完整的流程

(只启用redis 扩展 和 默认扩展)

要添加扩展,你只要依照添加redis 方式添加即可(过程中,你会发现需要解决很多很多静态链接库问题)

解决静态链接库问题,并且把解决步骤固定下来,也就是swoole-cli 项目做的事情

准备构建环境,alpine:3.17

运行容器,并将自动进入容器终端

docker run --rm   -ti --init  -w /work alpine:3.17

安装构建环境必要软件包

apk update

apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils gcc g++
apk add bash p7zip zip unzip flex pkgconf ca-certificates
apk add wget git curl
apk add libc++-static libltdl-static
apk add vim 

准备构建脚本

vi build-static-php.sh

#!/bin/env bash
set -uex

PHP_VERSION=8.1.21

test -f php-${PHP_VERSION}.tar.gz || wget -O php-${PHP_VERSION}.tar.gz https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz
test -d php-src && rm -rf php-src
mkdir -p php-src
tar --strip-components=1 -C php-src -xf php-${PHP_VERSION}.tar.gz

test -f redis-5.3.7.tgz || wget -O redis-5.3.7.tgz https://pecl.php.net/get/redis-5.3.7.tgz
mkdir -p redis
tar --strip-components=1 -C redis -xf redis-5.3.7.tgz

test -d php-src/ext/redis && rm -rf php-src/ext/redis
mv mongodb php-src/ext/

export CC=clang
export CXX=clang++
export LD=ld.lld

cd php-src

./buildconf --force

./configure \
  --disable-all \
  --disable-cgi \
  --enable-shared=no \
  --enable-static=yes \
  --enable-cli \
  --disable-phpdbg \
  --without-valgrind \
  --enable-session \
  --enable-redis

make -j $(nproc)

file sapi/cli/php
readelf -h sapi/cli/php

执行构建即可

bash build-static-php.sh

# 构建完毕 ,生成的如下文件,就是希望得到的二进制文件
sapi/cli/php 
sapi/cli/php -m 
sapi/cli/php -v 
sapi/cli/php --ri redis 

@jingjingxyk
Copy link
Contributor Author

jingjingxyk commented Jul 14, 2023

swoole-cli 就是在上述基础之上,做了进行裁剪 、优化、整合 、打包 等,并默认启用了swoole 扩展。

@jingjingxyk
Copy link
Contributor Author

一句命令即可 为 linux 、macOS 准备 PHP 运行环境 (依赖 curl 、wget 、bash 、xz)

curl https://github.com/swoole/swoole-cli/blob/main/setup-php-runtime.sh?raw=true -sSfL | bash -s -- --mirror china
curl https://swoole-cli.jingjingxyk.com/setup-php-runtime.sh  -sSf | bash -s -- --mirror china

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant