• Stars
    star
    252
  • Rank 161,312 (Top 4 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

micro sfx SAPI for php

micro 自执行SAPI

English readme

php License tests

micro自执行SAPI提供了php“自执行文件”的可能性

你只需要将构建的micro.sfx文件与任意php文件或者phar包拼接(cat或者copy /b)为一个文件就可以直接执行这个php文件

兼容性

目前兼容PHP8+;兼容Windows、Linux、macOS。

获取与使用

Github actions中构建了一个很少扩展的最小micro,如果需要扩展,请自行构建,参考下方构建说明或使用crazywhalecc/static-php-cli(swow/swoole/libevent)从lwmbs的workflow(swow)下一个

将micro.sfx和php文件拼接即可使用

例如:myawesomeapp.php内容为

<?php
echo "hello, this is my awesome app." . PHP_EOL;

linux/macOS下

注意:在macOS下如果你的micro.sfx是下载来的,运行时提示无法打开,可能需要执行下

sudo xattr -d com.apple.quarantine /path/to/micro.sfx

然后

cat /path/to/micro.sfx myawesomeapp.php > myawesomeapp
chmod 0755 ./myawesomeapp
./myawesomeapp
# 回显 "hello, this is my awesome app."

或者Windows下

COPY /b \path\to\micro.sfx + myawesomeapp.php myawesomeapp.exe
myawesomeapp.exe
REM 回显 "hello, this is my awesome app."

构建

准备源码

1.将本仓库clone到php源码的sapi/micro下

# 在php源码目录下
git clone <url for this repo> sapi/micro

2.打patch

patch文件在patches目录下,选择需要的patch文件,详细作用参考patches下的Readme.md

并分别进行patch:

# 在php源码目录下
patch -p1 < sapi/micro/patches/<name of patch>

unix-like 构建

0.参考官方构建说明准备PHP构建环境

1.buildconf

# 在php源码目录下
./buildconf --force

2.configure

# 在php源码目录下
./configure <options>

参考的选项:

--disable-phpdbg --disable-cgi --disable-cli --disable-all --enable-micro --enable-phar --with-ffi --enable-zlib

Linux下,存在C库兼容性问题,micro构建系统提供了两种选项:

  • --enable-micro=yes或者--enable-micro:这将会构建PIE的动态的micro,这种micro不能跨C库调用(即在alpine上构建的使用musl的micro不能在只安装了glibc的CentOS上使用,反过来也不能),但支持ffi和PHP的dl()函数。
  • --enable-micro=all-static:这将会构建静态的micro,这种micro不依赖C库,可以直接跑在支持的Linux内核上,但不能使用ffi/dl()

3.make

# 在php源码目录下
make micro

make all(或者make) 或许也可以,但建议还是只构建micro SAPI

生成的文件在 sapi/micro/micro.sfx

Windows 构建

0.参考官方构建说明准备PHP构建环境

1.buildconf

# 在php源码目录下
buildconf

2.configure

# 在php源码目录下
configure <options>

参考的选项:

--disable-all --disable-zts --enable-micro --enable-phar --with-ffi --enable-zlib

3.make 由于构建系统的实现问题, Windows下不能使用nmake命令直接构建,使用nmake micro来构建

# 在php源码目录下
nmake micro

生成的文件在 <架构名>\\<配置名>\\micro.sfx

优化

linux下php对于hugepages优化导致了生成的文件很大,如果不考虑对hugepages的优化,使用disable_huge_page.patch来来减小文件尺寸

linux下静态构建需要包含c标准库,常见的glibc较大,推荐使用musl,手动安装的musl或者某些发行版会提供gcc(或clang)的musl wrapper:musl-gcc或者musl-clang。在进行configure之前,通过指定CC和CXX变量来使用这些wrapper

例如

# ./buildconf things...
export CC=musl-gcc
export CXX=musl-gcc
# ./configure balabala
# make balabala

linux下构建时一般希望是纯静态的,但构建使用的发行版不一定提供依赖的库(zlib libffi等)的静态库版本,这时考虑自行构建依赖库

以libffi为例(all-static构建时不支持ffi):

# 通过git获取源码
git clone https://github.com/libffi/libffi
cd libffi
git checkout <version you like, v3.3 for example>
autoreconf -i
# 或者直接下载tarball解压
wget <url>
tar xf <tar name>
cd <extracted name>
# 如果使用musl的话
export CC=musl-gcc
export CXX=musl-gcc
# 构建安装
./configure --prefix=/my/prefered/path &&
make -j`nproc` &&
make install

然后使用以下export命令来构建micro:

# ./buildconf things...
# export CC=musl-xxx things...
export PKG_CONFIG_PATH=/my/prefered/path/lib/pkgconfig
# ./configure balabala
# make balabala

一些细节

INI配置

见wiki:INI-settings

PHP_BINARY常量

micro中这个常量是空字符串,可以通过ini配置:micro.php_binary=somestring

开源许可

Copyright 2020 Longyan

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

zui

ZUI is an HTML5 front UI framework.
TypeScript
2,700
star
2

zentaopms

Zentao is an agile(scrum) project management system/tool, Free Upgrade Forever!​
PHP
1,308
star
3

mzui

JavaScript
299
star
4

zendata

Go
250
star
5

zentaophp

zentaophp is a php mvc framework, light weight, extensionable.
PHP
168
star
6

zentaoatf

zentaoatf is an cross platform automation testing framework written in go language.
Go
164
star
7

zenshot

A screenshot tool
C++
160
star
8

phplibreoffice

A php extension for libreoffice.
C
67
star
9

phpsciter_old

phpsciter is a php extension to bind sciter, thus you can use php to develop GUI tools.
C++
58
star
10

phpsciter

The php extension of sciter. You can use it to build cross platform GUI app by php.
C++
58
star
11

zendev

程序员生存手册
53
star
12

phiwrapper

JavaScript
36
star
13

quickon

渠成企业软件百宝箱,众多软件一键安装,开箱即用。(QuickOn is an out-of-the-box platform for enterprise applications)
PHP
32
star
14

zos

ZOS is an light os run in virtual environment like virtualbox with lamp build in it.
HTML
22
star
15

zbox

PHP
21
star
16

zentaolicense

Z PUBLIC LICENSE, also known as ZPL Agreement is an open-source software license.
20
star
17

zentaoextension

the extension repo for zentao project management system.
PHP
16
star
18

go-zentao

ZenTao Go SDK
Go
13
star
19

zentaonotify

zentaonotify is a notify tools for zentaopms.
Pascal
12
star
20

zagent

Go
10
star
21

quickon_cli

About Install Qucheng , and related cloud-native add-ons, it supports all-in-one, multi-node, and HA 🔥 ⎈ 🐳
Go
7
star
22

xirangcsm

xirangcsm is a customer tracking system.
PHP
6
star
23

zentaowamp

zentaowamp is all-in-one runtime for zentao.
PHP
5
star
24

zentaolamp

zentaolamp是禅道linux集成运行环境。
PHP
4
star
25

zentao-vscode-integration

禅道 VS Code 集成扩展。从 VS Code 中快速跳转到禅道以查看需求、任务、Bug,并可以快速创建与之关联的 Commit Message。
JavaScript
3
star
26

zenpanel

C++
3
star
27

zentao_docker

zentao dockerlize
Makefile
3
star
28

qucheng_api

Go
1
star
29

zsiteextension

the extension repo for chanzhi enterprise portal system.
PHP
1
star
30

homebrew-tap

easysoft homebrew tap for Linux & macOS
Ruby
1
star
31

phiwrapper_binaries

binaries for phiwrapper
Shell
1
star
32

zentool

PHP
1
star
33

parquet

PHP
1
star