Skip to content

Commit

Permalink
Merge pull request #684 from jingjingxyk/build_native_php
Browse files Browse the repository at this point in the history
Build native php 同步功能代码
  • Loading branch information
jingjingxyk committed Jul 10, 2024
2 parents a02b9e4 + d3d0ee6 commit ef75a93
Show file tree
Hide file tree
Showing 64 changed files with 611 additions and 341 deletions.
2 changes: 1 addition & 1 deletion build-release-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ php -v
if [ ${WITH_PHP_COMPOSER} -eq 1 ] ; then
export COMPOSER_ALLOW_SUPERUSER=1
if [ "$MIRROR" = 'china' ]; then
composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
else
composer config -g repos.packagist composer https://packagist.org
Expand Down
25 changes: 21 additions & 4 deletions diff.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/usr/bin/env php
<?php
$list_swoole_cli = swoole_string(`./bin/swoole-cli -m | tail -n +2 | head -n -3`)->trim()->lower()->split(PHP_EOL)
$shell = "";
switch (PHP_OS) {
case 'Linux':
$shell = "./bin/swoole-cli -m | tail -n +2 | head -n -3 ";
break;
case 'Darwin':
$shell = "./bin/swoole-cli -m | tail -n +2 | ghead -n -3 ";
break;
case 'WINNT':
default:
echo "no support this OS ";
exit(0);

}
$list_swoole_cli = swoole_string(`$shell`)->trim()->lower()->split(PHP_EOL)
->remove('core');

$php_version_tag = trim(file_get_contents(__DIR__ . '/sapi/PHP-VERSION.conf'));
$php_source_folder = __DIR__ . '/var/php-' . $php_version_tag . '/ext/';
$list_php_src = swoole_string(`ls -1 {$php_source_folder}`)->trim()->lower()->split(PHP_EOL)
ob_start();
require_once __DIR__ . '/sapi/DownloadPHPSourceCode.php';
$php_source_folder = PHP_SRC_DIR;
ob_end_clean();

$list_php_src = swoole_string(`ls -1 {$php_source_folder}/ext/`)->trim()->lower()->split(PHP_EOL)
->remove('ext_skel.php')
->remove('zend_test');

Expand Down
104 changes: 54 additions & 50 deletions docs/extensions.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
# support extensions (x64)

| extension name | linux6 | macos | windows(cygwin) | default enabled |
|----------------|--------|-------|-----------------|----------------|
| curl | ||||
| iconv | ||||
| bcmath | ||||
| pcntl | ||||
| filter | ||||
| session | ||||
| tokenizer | ||||
| mbstring | ||||
| ctype | ||||
| zlib | ||||
| zip | ||||
| posix | ||||
| sockets | ||||
| pdo | ||||
| sqlite3 | ||||
| phar | ||||
| mysqlnd | ||||
| mysqli | ||||
| intl | ||||
| fileinfo | ||||
| pdo_mysql | ||||
| soap | ||||
| xsl | ||||
| gmp | ||||
| exif | ||||
| sodium | ||||
| openssl | ||||
| readline | ||||
| libxml | ||||
| xml | ||||
| xmlreader | ||||
| xmlwriter | ||||
| dom | ||||
| simplexml | ||||
| redis | ||||
| yaml | ||||
| imagick | ||||
| gd | ||||
| opcache | ||||
| swoole | ||||
| ssh2 | | || |
| apcu | ||||
| ds | || ||
| inotify | | | ||
| protobuf | ||||
| uuid | | |||
| mailparse | ||||
| mongodb | | |||
| extension name | linux | macos | windows(cygwin) | default enabled |
|----------------|-------|-------|-----------------|-----------------|
| curl |||| |
| iconv |||| |
| bcmath |||| |
| pcntl |||| |
| filter |||| |
| session |||| |
| tokenizer |||| |
| mbstring |||| |
| ctype |||| |
| zlib |||| |
| zip |||| |
| posix |||| |
| sockets |||| |
| pdo |||| |
| sqlite3 |||| |
| phar |||| |
| mysqlnd |||| |
| mysqli |||| |
| intl |||| |
| fileinfo |||| |
| pdo_mysql |||| |
| soap |||| |
| xsl |||| |
| gmp |||| |
| exif |||| |
| sodium |||| |
| openssl |||| |
| readline |||| |
| libxml |||| |
| xml |||| |
| xmlreader |||| |
| xmlwriter |||| |
| dom |||| |
| simplexml |||| |
| redis |||| |
| yaml |||| |
| imagick |||| |
| gd |||| |
| opcache |||| |
| swoole |||| |
| mongodb || || |
| ssh2 |||| |
| apcu ||| | |
| ds || | | |
| inotify | ||| |
| protobuf | | || |
| uuid |||| |
| mailparse | | |||

## 查看 新增的扩展 和 移除的扩展

```bash

./bin/swoole-cli diff.php

```
13 changes: 8 additions & 5 deletions docs/macOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,17 @@ export LIBSODIUM_LIBS=$(pkg-config --libs libsodium)

## Mac安装应用“提示文件已损坏”或“来自身份不明开发者”解决方法

> 解压以后执行如下命令:
> note: macos clearing the com.apple.quarantine extended attribute
> macos环境下 首次运行提示无权限 ,通过清除扩展属性 解决
```bash
# 查看扩展属性
xattr ./bin/swoole-cli
# 移除扩展属性
sudo xattr -d com.apple.quarantine ./bin/swoole-cli

sudo xattr -d com.apple.quarantine ./swoole-cli

file ./bin/swoole-cli
otool -L ./bin/swoole-cli
file ./bin/swoole-cli
otool -L ./bin/swoole-cli

```

Expand Down
15 changes: 15 additions & 0 deletions docs/upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 升级 PHP 版本 步骤

> 1、修改 sapi/PHP-VERSION.conf 文件里版本号即可
> 2、执行同步源码脚本, 拉取 PHP 官方源码 到本项目
```shell

# 测试同步源码
php sync-source-code.php

# 正式同步源码
php sync-source-code.php --action run


```
29 changes: 29 additions & 0 deletions sapi/DownloadPHPSourceCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$poject_dir = realpath(__DIR__ . '/../');
# $php_version_tag = trim(file_get_contents($poject_dir . '/sapi/PHP-VERSION.conf'));
$php_version_tag = "8.2.13";
define("PHP_SRC_DIR", $poject_dir . "/var/php-{$php_version_tag}");
$php_source_folder = PHP_SRC_DIR;
$php_file = $poject_dir . "/pool/lib/php-{$php_version_tag}.tar.gz";
$download_dir = dirname($php_file);


# 下载 PHP 源码
$DOWNLOAD_PHP_CMD = "curl -L https://github.com/php/php-src/archive/refs/tags/php-{$php_version_tag}.tar.gz -o {$php_file}";
echo $DOWNLOAD_PHP_CMD . PHP_EOL;
if (!file_exists($php_file)) {
`test -d {$download_dir} || mkdir -p {$download_dir}`;
`{$DOWNLOAD_PHP_CMD}`;
}

# 解压 PHP 源码
# tar -zxvf 文件名.tar.gz --strip-components=1 -C 指定解压目录
$UNTAR_PHP_SOURCE_CMD = <<<EOF
set -x
# test -d {$php_source_folder} && rm -rf {$php_source_folder}
mkdir -p {$php_source_folder}
test -f {$php_source_folder}/configure.ac || tar -zxf {$php_file} --strip-components=1 -C {$php_source_folder}
EOF;

`{$UNTAR_PHP_SOURCE_CMD}`;
5 changes: 4 additions & 1 deletion sapi/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM alpine:3.18
ARG BASE_IMAGE="alpine:3.18"
FROM ${BASE_IMAGE}
# FROM alpine:3.18


ARG MIRROR=""

Expand Down
31 changes: 0 additions & 31 deletions sapi/docker/Dockerfile-arm64

This file was deleted.

77 changes: 51 additions & 26 deletions sapi/docker/build-export-container.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

:<<'COMMENT'
从运行中的容器 将 /usr/local/swoole-cli/ 文件夹 拷贝出来 并生成新容器镜像 和 导出镜像到磁盘
COMMENT

set -exu
__DIR__=$(
cd "$(dirname "$0")"
Expand All @@ -12,6 +17,42 @@ __PROJECT__=$(
cd ${__DIR__}
cd ${__PROJECT__}


CONTAINER_BASE_IMAGE='docker.io/library/alpine:3.18'
MIRROR=''
PLATFORM=''
ARCH=$(uname -m)
case $ARCH in
'x86_64')
PLATFORM='linux/amd64'
;;
'aarch64')
PLATFORM='linux/arm64'
;;
esac

while [ $# -gt 0 ]; do
case "$1" in
--platform)
PLATFORM="$2"
;;
--mirror)
MIRROR="$2"
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(($# > 0 ? 1 : 0))
done

case "$MIRROR" in
china | openatom)
CONTAINER_BASE_IMAGE="hub.atomgit.com/library/alpine:3.18"
;;
esac


mkdir -p var/build-export-container/
cd ${__PROJECT__}/var/build-export-container/

Expand All @@ -22,13 +63,18 @@ docker cp $container_id:/usr/local/swoole-cli/ .


cat > Dockerfile <<'EOF'
FROM alpine:3.18
ARG BASE_IMAGE="alpine:3.18"
FROM ${BASE_IMAGE}
# FROM alpine:3.18
ARG MIRROR=""
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV TZ=Etc/UTC
RUN test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN if [ "${MIRROR}" = "ustc" -o "${MIRROR}" = "china" ]; then { sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; } fi
RUN if [ "${MIRROR}" = "tuna" ]; then { sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories ; } fi
RUN apk add ca-certificates tini
ADD ./swoole-cli /usr/local/swoole-cli
Expand All @@ -44,37 +90,16 @@ EOF



PLATFORM=''
ARCH=$(uname -m)
case $ARCH in
'x86_64')
PLATFORM='linux/amd64'
;;
'aarch64')
PLATFORM='linux/arm64'
;;
esac

while [ $# -gt 0 ]; do
case "$1" in
--platform)
PLATFORM="$2"
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(($# > 0 ? 1 : 0))
done

ARCH=$(uname -m)
TIME=$(date -u '+%Y%m%dT%H%M%SZ')
VERSION="1.6"
TAG="v${VERSION}-${ARCH}-${TIME}"

IMAGE="docker.io/phpswoole/swoole-cli-builder:${TAG}"

docker build -t ${IMAGE} -f ./Dockerfile . --progress=plain --platform ${PLATFORM}
echo "MIRROR=${MIRROR}"
echo "BASE_IMAGE=${CONTAINER_BASE_IMAGE}"
docker build -t ${IMAGE} -f ./Dockerfile . --progress=plain --platform ${PLATFORM} --build-arg="MIRROR=${MIRROR}" --build-arg="BASE_IMAGE=${CONTAINER_BASE_IMAGE}"

echo ${IMAGE}
echo ${IMAGE} > container-image.txt
Expand Down
2 changes: 1 addition & 1 deletion sapi/quickstart/linux/run-alpine-container-full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ while [ $# -gt 0 ]; do
--mirror)
MIRROR="$2"
;;
--dev-shm)
--dev-shm) #使用 /dev/shm 目录加快构建速度
DEV_SHM=1
;;
esac
Expand Down
Loading

0 comments on commit ef75a93

Please sign in to comment.