From 01615a8945fe890ff0d1347eb5fa0b69c7043230 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 1 Jul 2024 02:29:38 +0000 Subject: [PATCH] deploy: 1f6f98aefe157e2759c6591bf192d9691ea2af21 --- 404.html | 2 +- CNAME | 1 + en/contributing/index.html | 2 +- en/develop/doctor-module.html | 2 +- en/develop/index.html | 2 +- en/develop/source-module.html | 2 +- en/develop/structure.html | 2 +- en/develop/system-build-tools.html | 2 +- en/faq/index.html | 2 +- en/guide/action-build.html | 2 +- en/guide/build-on-windows.html | 2 +- en/guide/cli-generator.html | 2 +- en/guide/env-vars.html | 2 +- en/guide/extension-notes.html | 2 +- en/guide/extensions.html | 2 +- en/guide/index.html | 2 +- en/guide/manual-build.html | 2 +- en/guide/troubleshooting.html | 2 +- en/index.html | 2 +- extension-notes.html | 2 +- extensions.html | 2 +- hashmap.json | 2 +- index.html | 2 +- zh/contributing/index.html | 2 +- zh/develop/doctor-module.html | 2 +- zh/develop/index.html | 2 +- zh/develop/source-module.html | 2 +- zh/develop/structure.html | 2 +- zh/develop/system-build-tools.html | 2 +- zh/faq/index.html | 2 +- zh/guide/action-build.html | 2 +- zh/guide/build-on-windows.html | 2 +- zh/guide/cli-generator.html | 2 +- zh/guide/env-vars.html | 2 +- zh/guide/extension-notes.html | 2 +- zh/guide/extensions.html | 2 +- zh/guide/index.html | 2 +- zh/guide/manual-build.html | 2 +- zh/guide/troubleshooting.html | 2 +- zh/index.html | 2 +- 40 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 CNAME diff --git a/404.html b/404.html index 587102f7..c29b0e2a 100644 --- a/404.html +++ b/404.html @@ -15,7 +15,7 @@
Skip to content

404

PAGE NOT FOUND

But if you don't change your direction, and if you keep looking, you may end up where you are heading.
- + \ No newline at end of file diff --git a/CNAME b/CNAME new file mode 100644 index 00000000..f0282be4 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +static-php.dev \ No newline at end of file diff --git a/en/contributing/index.html b/en/contributing/index.html index c42bb02c..d40b2017 100644 --- a/en/contributing/index.html +++ b/en/contributing/index.html @@ -18,7 +18,7 @@
Skip to content

Contributing

Thank you for being here, this project welcomes your contributions!

Contribution Guide

If you have code or documentation to contribute, here's what you need to know first.

  1. What type of code are you contributing? (new extensions, bug fixes, security issues, project framework optimizations, documentation)
  2. If you contribute new files or new snippets, is your code checked by php-cs-fixer and phpstan?
  3. Have you fully read the Developer Guide before contributing code?

If you can answer the above questions and have made changes to the code, you can initiate a Pull Request in the project GitHub repository in time. After the code review is completed, the code can be modified according to the suggestion, or directly merged into the main branch.

Contribution Type

The main purpose of this project is to compile statically linked PHP binaries, and the command line processing function is written based on symfony/console. Before development, if you are not familiar with it, Check out the symfony/console documentation first.

Security Update

Because this project is basically a PHP project running locally, generally speaking, there will be no remote attacks. But if you find such a problem, please **DO NOT submit a PR or Issue in the GitHub repository, You need to contact the project maintainer (crazywhalecc) via mail.

Fix Bugs

Fixing bugs generally does not involve modification of the project structure and framework, so if you can locate the wrong code and fix it directly, please submit a PR directly.

New Extensions

For adding a new extension, you need to understand some basic structure of the project and how to add a new extension according to the existing logic. It will be covered in detail in the next section on this page. In general, you will need:

  1. Evaluate whether the extension can be compiled inline into PHP.
  2. Evaluate whether the extension's dependent libraries (if any) can be compiled statically.
  3. Write library compile commands on different platforms.
  4. Verify that the extension and its dependencies are compatible with existing extensions and dependencies.
  5. Verify that the extension works normally in cli, micro, fpm, embed SAPIs.
  6. Write documentation and add your extension.

Project Framework Optimization

If you are already familiar with the working principle of symfony/console, and at the same time want to make some modifications or optimizations to the framework of the project, please understand the following things first:

  1. Adding extensions does not belong to project framework optimization, but if you find that you have to optimize the framework when adding new extensions, you need to modify the framework itself before adding extensions.
  2. For some large-scale logical modifications (such as those involving LibraryBase, Extension objects, etc.), it is recommended to submit an Issue or Draft PR for discussion first.
  3. In the early stage of the project, it was a pure private development project, and there were some Chinese comments in the code. After internationalizing your project you can submit a PR to translate these comments into English.
  4. Please do not submit more useless code fragments in the code, such as a large number of unused variables, methods, classes, and code that has been rewritten many times.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/develop/doctor-module.html b/en/develop/doctor-module.html index 163c24e4..c11d58ea 100644 --- a/en/develop/doctor-module.html +++ b/en/develop/doctor-module.html @@ -46,7 +46,7 @@ } return true; }

#[AsFixItem()] first parameter is the name of the fix item, and this method must return True or False. When False is returned, the automatic repair failed and manual handling is required.

In the code here, shell()->exec() is the method of executing commands of the project, which is used to replace exec() and system(), and also provides debugging, obtaining execution status, entering directories, etc. characteristic.

- + \ No newline at end of file diff --git a/en/develop/index.html b/en/develop/index.html index 097f3e0c..914ec617 100644 --- a/en/develop/index.html +++ b/en/develop/index.html @@ -18,7 +18,7 @@
Skip to content

Start Developing

Developing this project requires the installation and deployment of a PHP environment, as well as some extensions and Composer commonly used in PHP projects.

The development environment and running environment of the project are almost exactly the same. You can refer to the Manual Build section to install system PHP or use the pre-built static PHP of this project as the environment. I will not go into details here.

Regardless of its purpose, this project itself is actually a php-cli program. You can edit and develop it as a normal PHP project. At the same time, you need to understand the Shell languages of different systems.

The current purpose of this project is to compile statically compiled independent PHP, but the main part also includes compiling static versions of many dependent libraries, so you can reuse this set of compilation logic to build independent binary versions of other programs, such as Nginx, etc.

Environment preparation

A PHP environment is required to develop this project. You can use the PHP that comes with the system, or you can use the static PHP built by this project.

Regardless of which PHP you use, in your development environment you need to install these extensions:

curl,dom,filter,mbstring,openssl,pcntl,phar,posix,sodium,tokenizer,xml,xmlwriter

The static-php-cli project itself does not require so many extensions, but during the development process, you will use tools such as Composer and PHPUnit, which require these extensions.

For micro self-executing binaries built by static-php-cli itself, only pcntl,posix,mbstring,tokenizer,phar is required.

Start development

Continuing down to see the project structure documentation, you can learn how static-php-cli works.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/develop/source-module.html b/en/develop/source-module.html index 31e20f43..03a02b7c 100644 --- a/en/develop/source-module.html +++ b/en/develop/source-module.html @@ -122,7 +122,7 @@ ] } } - + \ No newline at end of file diff --git a/en/develop/structure.html b/en/develop/structure.html index 7ce812a1..6bf3a9a5 100644 --- a/en/develop/structure.html +++ b/en/develop/structure.html @@ -27,7 +27,7 @@ box.json # Configuration file for packaging Phar another-app.php # Entry file of another project vendor/crazywhalecc/static-php-cli/* # Your project is used as a dependent library

When packaging these files under the directory /home/example/another-app/ into app.phar, the value of the following constant for your project should be:

ConstantValue
WORKING_DIR/home/example/another-app
SOURCE_ROOT_DIRphar:///home/example/another-app/app.phar/
FRAMEWORK_ROOT_DIRphar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli
__DIR__phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App
__FILE__phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App/MyCommand.php
- + \ No newline at end of file diff --git a/en/develop/system-build-tools.html b/en/develop/system-build-tools.html index f2b3bf32..8822e1dd 100644 --- a/en/develop/system-build-tools.html +++ b/en/develop/system-build-tools.html @@ -85,7 +85,7 @@ make TARGET=x86_64-linux-musl -j make TARGET=x86_64-linux-musl install -j tar cvzf x86_64-musl-toolchain.tgz output/*

TIP

All the above scripts are suitable for x86_64 architecture Linux. If you need to build musl-cross-make for the ARM environment, just replace all x86_64 above with aarch64.

This compilation process may fail due to insufficient memory, network problems, etc. You can try a few more times, or use a machine with larger memory to compile. If you encounter problems or you have better improvement solutions, go to Discussion.

macOS Environment

For macOS systems, the main compilation tool we use is clang, which is the default compiler for macOS systems and is also the compiler of Xcode.

Compiling under macOS mainly relies on Xcode or Xcode Command Line Tools. You can download Xcode from the App Store, or execute xcode-select --install in the terminal to install Xcode Command Line Tools.

In addition, in the doctor environment check module, static-php-cli will check whether Homebrew, compilation tools, etc. are installed on the macOS system. If not, you will be prompted to install them. I will not go into details here.

FreeBSD Environment

FreeBSD is also a Unix system, and its compilation tools are similar to macOS. You can directly use the package management pkg to install clang and other compilation tools through the doctor command.

pkg-config Compilation (*nix only)

If you observe the compilation log when using static-php-cli to build static PHP, you will find that no matter what is compiled, pkg-config will be compiled first. This is because pkg-config is a library used to find dependencies. In earlier versions of static-php-cli, we directly used the pkg-config tool installed by package management, but this would cause some problems, such as:

In order to avoid the above problems, we compile pkg-config into buildroot/bin in user mode and use it. We use parameters such as --without-sysroot to avoid looking for dependent packages from the system path.

- + \ No newline at end of file diff --git a/en/faq/index.html b/en/faq/index.html index 917a02ea..e7230c55 100644 --- a/en/faq/index.html +++ b/en/faq/index.html @@ -19,7 +19,7 @@
Skip to content

FAQ

Here will be some questions that you may encounter easily. There are currently many, but I need to take time to organize them.

Can statically compiled PHP install extensions?

Because the principle of installing extensions in PHP under the traditional architecture is to install new extensions using .so type dynamic link libraries, and statically linked PHP compiled using this project cannot directly install new extensions using dynamic link libraries.

For the macOS platform, almost all binary files under macOS cannot be linked purely statically, and almost all binary files will link macOS system libraries: /usr/lib/libresolv.9.dylib and /usr/lib/libSystem.B.dylib. So under macOS system, statically compiled php binary files can be used under certain compilation conditions, and dynamic link extensions can be used at the same time:

  1. Using the --no-strip parameter will not strip information such as debugging symbols from the binary file for use with external Zend extensions such as Xdebug.
  2. If you want to compile some Zend extensions, use Homebrew, MacPorts, source code compilation, and install a normal version of PHP on your operating system.
  3. Use the phpize && ./configure && make command to compile the extensions you want to use.
  4. Copy the extension file xxxx.so to the outside, use the statically compiled PHP binary, for example to use the Xdebug extension: cd buildroot/bin/ && ./php -d "zend_extension=/path/to/xdebug.so".
bash
# build statically linked php-cli but not stripped
 bin/spc build ffi --build-cli --no-strip

For the Linux platform, the current compilation result is a purely statically linked binary file, and new extensions cannot be installed using a dynamic link library.

Can it support Oracle database extension?

Some extensions that rely on closed source libraries, such as oci8, sourceguardian, etc., they do not provide purely statically compiled dependent library files (.a), only dynamic dependent library files (.so). These extensions cannot be compiled into static-php-cli from source, so this project may never support them. However, in theory, you can access and use such extensions under macOS according to the above questions.

If you have a need for such extensions, or most people have needs for these closed-source extensions, see the discussion on standalone-php-cli. Welcome to leave a message.

Does it support Windows?

The project currently supports Windows, but the number of supported extensions is small. Windows support is not perfect. There are mainly the following problems:

  1. The compilation process of Windows is different from that of *nix, and the toolchain used is also different. The compilation tools used to compile the dependent libraries of each extension are almost completely different.
  2. The demand for the Windows version will also be advanced based on the needs of all people who use this project. If many people need it, I will support related extensions as soon as possible.

Can I protect my source code with micro?

You can't. micro.sfx is essentially combining php and php code into one file, there is no process of compiling or encrypting the PHP code.

First of all, php-src is the official interpreter of PHP code, and there is no PHP compiler compatible with mainstream branches on the market. I saw on the Internet that there is a project called BPC (Binary PHP Compiler?) that can compile PHP into binary, but there are many restrictions.

The direction of encrypting and protecting the code is not the same as compiling. After compiling, the code can also be obtained through reverse engineering and other methods. The real protection is still carried out by means of packing and encrypting the code.

Therefore, this project (static-php-cli) and related projects (lwmbs, swoole-cli) all provide a convenient compilation tool for php-src source code. The phpmicro referenced by this project and related projects is only a package of PHP's sapi interface, not a compilation tool for PHP code. The compiler for PHP code is a completely different project, so the extra cases are not taken into account. If you are interested in encryption, you can consider using existing encryption technologies, such as Swoole Compiler, Source Guardian, etc.

Unable to use ssl

When using curl, pgsql, etc. to request an HTTPS website or establish an SSL connection, there may be an error:80000002:system library::No such file or directory error. This error is caused by statically compiled PHP without specifying openssl.cafile via php.ini.

You can solve this problem by specifying php.ini before using PHP and adding openssl.cafile=/path/to/your-cert.pem in the INI.

For Linux systems, you can download the cacert.pem file from the curl official website, or you can use the certificate file that comes with the system. For the certificate locations of different distros, please refer to Golang docs.

INI configuration openssl.cafile cannot be set dynamically using the ini_set() function, because openssl.cafile is a PHP_INI_SYSTEM type configuration and can only be set in the php.ini file.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/guide/action-build.html b/en/guide/action-build.html index 7e7ec263..af4d30f2 100644 --- a/en/guide/action-build.html +++ b/en/guide/action-build.html @@ -18,7 +18,7 @@
Skip to content

GitHub Action Build

Action Build refers to compiling directly using GitHub Action.

If you don't want to compile it yourself, you can download the artifact from the existing Action in this project, or you can download it from a self-hosted server:Enter.

Self-hosted binaries are also built from Actions: repo. The extensions included are: bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl, pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip

Build Guide

Using GitHub Action makes it easy to build a statically compiled PHP and phpmicro, while also defining the extensions to compile.

  1. Fork project.
  2. Go to the Actions of the project and select CI.
  3. Select Run workflow, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. bcmath,curl,mbstring)
  4. After waiting for about a period of time, enter the corresponding task and get Artifacts.

If you enable debug, all logs will be output at build time, including compiled logs, for troubleshooting.

If you need to build in other environments, you can use manual build.

Extensions

You can go to extensions check here to see if all the extensions you need currently support. and then go to command generator select the extension you need to compile, copy the extensions string to extensions option.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/guide/build-on-windows.html b/en/guide/build-on-windows.html index 59155371..cfb6300c 100644 --- a/en/guide/build-on-windows.html +++ b/en/guide/build-on-windows.html @@ -40,7 +40,7 @@ bin/spc micro:combine code.php -O my-app.exe # Run it!!! Copy it to another computer!!! ./my-app.exe

If you package a PHAR file, just replace code.php with the phar file path. You can use box-project/box to package your CLI project as Phar, It is then combined with phpmicro to produce a standalone executable binary.

For more details on the micro:combine command, refer to command on Unix systems.

- + \ No newline at end of file diff --git a/en/guide/cli-generator.html b/en/guide/cli-generator.html index 9169a0f1..7349e54f 100644 --- a/en/guide/cli-generator.html +++ b/en/guide/cli-generator.html @@ -19,7 +19,7 @@
Skip to content

CLI Build Command Generator

TIP

The extensions selected below may contain extensions that are not supported by the selected operating system, which may cause compilation to fail. Please check Supported Extensions first.

Select Build OS

Select Extensions

Select common extensions
Unselect all
Select Dependencies

TIP

After selecting the extensions, the unselectable items are essential dependencies. In the compiled dependencies list, optional dependencies consist of existing extensions and optional dependencies of libraries. Optional dependencies will be added in --with-libs parameter.

Build Target

Build Options

Build Environment
Download PHP version
Enable debug message
Enable ZTS
Download with corresponding extension dependencies
Enable UPX compression (reduce binary size, but in rare cases micro SAPI doesn't work with UPX)

Hardcoded INI options

Result

Download sources by extensions command
bin/spc download --with-php=8.2 --for-extensions ""
Compile command
bin/spc build --build-cli ""

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/guide/env-vars.html b/en/guide/env-vars.html index a48f9c74..d317b096 100644 --- a/en/guide/env-vars.html +++ b/en/guide/env-vars.html @@ -23,7 +23,7 @@ # or direct use SPC_CONCURRENCY=4 bin/spc build mbstring,pcntl --build-cli

General environment variables

General environment variables can be used by all build targets.

var namedefault valuecomment
BUILD_ROOT_PATH{pwd}/buildrootThe root directory of the build target
BUILD_LIB_PATH{pwd}/buildroot/libThe root directory of compilation libraries
BUILD_INCLUDE_PATH{pwd}/buildroot/includeHeader file directory for compiling libraries
BUILD_BIN_PATH{pwd}/buildroot/binCompiled binary file directory
PKG_ROOT_PATH{pwd}/pkgrootDirectory where precompiled tools are installed
SOURCE_PATH{pwd}/sourceThe source code extract directory
DOWNLOAD_PATH{pwd}/downloadsDownloaded file directory
SPC_CONCURRENCYDepends on CPU coresNumber of parallel compilations
SPC_SKIP_PHP_VERSION_CHECKemptySkip PHP version check when set to yes

OS specific variables

These environment variables are system-specific and will only take effect on a specific OS.

Windows

var namedefault valuecomment
PHP_SDK_PATH{pwd}\php-sdk-binary-toolsPHP SDK tools path
UPX_EXEC$PKG_ROOT_PATH\bin\upx.exeUPX compression tool path

macOS

var namedefault valuecomment
CCclangC Compiler
CXXclang++C++ Compiler
SPC_DEFAULT_C_FLAGS--target=arm64-apple-darwin or --target=x86_64-apple-darwinDefault C flags (not the same as CFLAGS)
SPC_DEFAULT_CXX_FLAGS--target=arm64-apple-darwin or --target=x86_64-apple-darwinDefault C flags (not the same as CPPFLAGS)
SPC_CMD_PREFIX_PHP_BUILDCONF./buildconf --forcePHP buildconf command prefix
SPC_CMD_PREFIX_PHP_CONFIGURE./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbgPHP configure command prefix
SPC_CMD_PREFIX_PHP_MAKEmake -j$SPC_CONCURRENCYPHP make command prefix
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS$SPC_DEFAULT_C_FLAGS -Werror=unknown-warning-optionCFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS-I$BUILD_INCLUDE_PATHCPPFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS-L$BUILD_LIB_PATHLDFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS-g0 -Os or -g -O0 (the latter when using --no-strip)EXTRA_CFLAGS variable of PHP make command
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS-lresolvExtra EXTRA_LIBS variables for PHP make command

Linux

var namedefault valuecomment
UPX_EXEC$PKG_ROOT_PATH/bin/upxUPX compression tool path
GNU_ARCHx86_64 or aarch64CPU architecture
CCAlpine: gcc, Other: $GNU_ARCH-linux-musl-gccC Compiler
CXXAlpine: g++, Other: $GNU_ARCH-linux-musl-g++C++ Compiler
ARAlpine: ar, Other: $GNU_ARCH-linux-musl-arStatic library tools
LDld.goldLinker
PATH/usr/local/musl/bin:/usr/local/musl/$GNU_ARCH-linux-musl/bin:$PATHSystem PATH
SPC_DEFAULT_C_FLAGSemptyDefault C flags
SPC_DEFAULT_CXX_FLAGSemptyDefault C++ flags
SPC_CMD_PREFIX_PHP_BUILDCONF./buildconf --forcePHP buildconf command prefix
SPC_CMD_PREFIX_PHP_CONFIGURELD_LIBRARY_PATH={ld_lib_path} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbgPHP configure command prefix
SPC_CMD_PREFIX_PHP_MAKEmake -j$SPC_CONCURRENCYPHP make command prefix
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS$SPC_DEFAULT_C_FLAGSCFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS-I$BUILD_INCLUDE_PATHCPPFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS-L$BUILD_LIB_PATHLDFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_LIBS-ldl -lpthreadLIBS variable of PHP configure command
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS-g0 -Os -fno-ident -fPIE or -g -O0 -fno-ident -fPIE (the latter when using --no-strip)EXTRA_CFLAGS variable of PHP make command
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBSemptyExtra EXTRA_LIBS variables for PHP make command
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM-all-static (when using clang: -Xcompiler -fuse-ld=lld -all-static)Additional LDFLAGS variable for make command
SPC_NO_MUSL_PATHemptyWhether to not insert the PATH of the musl toolchain (not inserted when the value is yes)

{ld_lib_path} value is /usr/local/musl/$GNU_ARCH-linux-musl/lib

FreeBSD

Due to the small number of users of the FreeBSD system, we do not provide environment variables for the FreeBSD system for the time being.

Unix

For Unix systems such as macOS, Linux, FreeBSD, etc., the following environment variables are common.

var namedefault valuecomment
PATH$BUILD_BIN_PATH:$PATHSystem PATH
PKG_CONFIG_PATH$BUILD_LIB_PATH/pkgconfigpkg-config search path
PKG_CONFIG$BUILD_BIN_PATH/pkg-configpkg-config executable path

Library Environment variables (Unix only)

Starting from 2.2.0, static-php-cli supports custom environment variables for all compilation dependent library commands of macOS, Linux, FreeBSD and other Unix systems.

In this way, you can adjust the behavior of compiling dependent libraries through environment variables at any time. For example, you can set the optimization parameters for compiling the xxx library through xxx_CFLAGS=-O0.

Of course, not every library supports the injection of environment variables. We currently provide three wildcard environment variables with the suffixes:

The prefix is the name of the dependent library, and the specific name of the library is subject to lib.json. Among them, the library name with - needs to replace - with _.

Here is an example of an optimization option that replaces the openssl library compilation:

shell
openssl_CFLAGS="-O0"

The library name uses the same name listed in lib.json and is case-sensitive.

TIP

When no relevant environment variables are specified, except for the following variables, the remaining values are empty by default:

var namevar default value
pkg_config_CFLAGSmacOS: $SPC_DEFAULT_C_FLAGS -Wimplicit-function-declaration -Wno-int-conversion, Other: empty
pkg_config_LDFLAGSLinux: --static, Other: empty
imagemagick_LDFLAGSLinux: -static, Other: empty
imagemagick_LIBSmacOS: -liconv, Other: empty
ldap_LDFLAGS-L$BUILD_LIB_PATH
openssl_CFLAGSLinux: $SPC_DEFAULT_C_FLAGS, Other: empty
others...empty

The following table is a list of library names that support customizing the above three variables:

lib name
brotli
bzip
curl
freetype
gettext
gmp
imagemagick
ldap
libargon2
libavif
libcares
libevent
openssl

TIP

Because adapting custom environment variables to each library is a particularly tedious task, and in most cases you do not need custom environment variables for these libraries, so we currently only support custom environment variables for some libraries.

If the library you need to customize environment variables is not listed above, you can submit your request through GitHub Issue.

- + \ No newline at end of file diff --git a/en/guide/extension-notes.html b/en/guide/extension-notes.html index 39980196..d4e264e1 100644 --- a/en/guide/extension-notes.html +++ b/en/guide/extension-notes.html @@ -18,7 +18,7 @@
Skip to content

Extension Notes

Because it is a static compilation, extensions will not compile 100% perfectly, and different extensions have different requirements for PHP and the environment, which will be listed one by one here.

curl

When using curl to request HTTPS, there may be an error:80000002:system library::No such file or directory error. For details on the solution, see FAQ - Unable to use ssl.

phpmicro

  1. Only PHP >= 8.0 is supported.

swoole

  1. swoole >= 5.0 Only PHP >= 8.0 is supported.
  2. swoole Currently, curl hooks are not supported for PHP 8.0.x (which may be fixed in the future).
  3. When compiling, if only swoole extension is included, the supported Swoole database coroutine hook will not be fully enabled. If you need to use it, please add the corresponding swoole-hook-xxx extension.
  4. The zend_mm_heap corrupted problem may occur in swoole under some extension combinations. The cause has not yet been found.

swoole-hook-pgsql

swoole-hook-pgsql is not an extension, it's a Hook feature of Swoole. If you use swoole,swoole-hook-pgsql, you will enable Swoole's PostgreSQL client and the coroutine mode of the pdo_pgsql extension.

swoole-hook-pgsql conflicts with the pdo_pgsql extension. If you want to use Swoole and pdo_pgsql, please delete the pdo_pgsql extension and enable swoole and swoole-hook-pgsql. This extension contains an implementation of the coroutine environment for pdo_pgsql.

On macOS systems, pdo_pgsql may not be able to connect to the postgresql server normally, please use it with caution.

swoole-hook-mysql

swoole-hook-mysql is not an extension, it's a Hook feature of Swoole. If you use swoole,swoole-hook-mysql, you will enable the coroutine mode of Swoole's mysqlnd and pdo_mysql.

swoole-hook-sqlite

swoole-hook-sqlite is not an extension, it's a Hook feature of Swoole. If you use swoole,swoole-hook-sqlite, you will enable the coroutine mode of Swoole's pdo_sqlite (Swoole must be 5.1 or above).

swoole-hook-sqlite conflicts with the pdo_sqlite extension. If you want to use Swoole and pdo_sqlite, please delete the pdo_sqlite extension and enable swoole and swoole-hook-sqlite. This extension contains an implementation of the coroutine environment for pdo_sqlite.

swow

  1. Only PHP version >= 8.0 is supported.

imap

  1. Kerberos is not supported
  2. ext-imap is not thread safe due to the underlying c-client. It's not possible to use it in --enable-zts builds.
  3. Because the extension may be dropped from php, we recommend you look for an alternative implementation, such as Webklex/php-imap

gd

  1. gd Extension relies on more additional Graphics library. By default, using bin/spc build gd directly will not support some Graphics library, such as libjpeg, libavif, etc. Currently, it supports four libraries: freetype,libjpeg,libavif,libwebp. Therefore, the following command can be used to introduce them into the gd library:
bash
bin/spc build gd --with-libs=freetype,libjpeg,libavif,libwebp --build-cli

mcrypt

  1. Currently not supported, and this extension will not be supported in the future. #32

oci8

  1. oci8 is an extension of the Oracle database, because the library on which the extension provided by Oracle does not provide a statically compiled version (.a) or source code, and this extension cannot be compiled into php by static linking, so it cannot be supported.

xdebug

  1. Xdebug is a Zend extension. The functions of Xdebug depend on PHP's Zend engine and underlying code. If you want to statically compile it into PHP, you may need a huge amount of patch code, which is not feasible.
  2. The macOS platform can compile an xdebug extension under PHP compiled on the same platform, extract the xdebug.so file, and then use the --no-strip parameter in static-php-cli to retain the debug symbol table and add the ffi extension. The compiled ./php binary can be configured and run by specifying the INI, eg ./php -d 'zend_extension=/path/to/xdebug.so' your-code.php.

xml

  1. xml includes xml, xmlreader, xmlwriter, xsl, dom, simplexml, etc. When adding xml extensions, it is best to enable these extensions at the same time.
  2. libxml is included in xml extension. Enabling xml is equivalent to enabling libxml.

glfw

  1. glfw depends on OpenGL, and linux environment also needs X11, which cannot be linked statically.
  2. macOS platform, we can compile and link system builtin OpenGL and related libraries dynamically.

rar

  1. The rar extension currently has a problem when compiling phpmicro with the common extension collection in the macOS x86_64 environment.

pgsql

pgsql ssl connection is not compatible with openssl 3.2.0. See:

pgsql 16.2 has fixed this bug, now it's working.

When pgsql uses SSL connection, there may be error:80000002:system library::No such file or directory error, For details on the solution, see FAQ - Unable to use ssl.

openssl

When using openssl-based extensions (such as curl, pgsql and other network libraries), there may be an error:80000002:system library::No such file or directory error. For details on the solution, see FAQ - Unable to use ssl.

password-argon2

  1. password-argon2 is not a standard extension, it is an additional algorithm for the password_hash function.
  2. On Linux systems, password-argon2 dependency libargon2 conflicts with the libsodium library.

ffi

  1. Linux not supported yet: Due to limitations of the Linux system, although the ffi extension can be compiled successfully, it cannot be used to load other so extensions. The prerequisite for Linux to support loading so extensions is dynamic compilation, but dynamic compilation conflicts with the purpose of this project.
  2. macOS supports the ffi extension, but errors will occur when some kernels do not contain debugging symbols.
  3. Windows x64 supports the ffi extension.

xhprof

The xhprof extension consists of three parts: xhprof_extension, xhprof_html, xhprof_libs. Only xhprof_extension is included in the compiled binary. If you need to use xhprof, please download the source code from pecl.php.net/package/xhprof and specify the xhprof_libs and xhprof_html paths for use.

event

If you enable event extension on macOS, the openpty will be disabled due to issue:

parallel

Parallel is only supported on PHP 8.0 ZTS and above.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/guide/extensions.html b/en/guide/extensions.html index 60b99ee3..85e2de43 100644 --- a/en/guide/extensions.html +++ b/en/guide/extensions.html @@ -18,7 +18,7 @@
Skip to content

Extensions

  • yes: supported
  • blank: not supported yet, or WIP
  • no with issue link: confirmed to be unavailable due to issue
  • partial with issue link: supported but not perfect due to issue
Extension NameLinuxmacOSFreeBSDWindows
amqpyesyesyes
apcuyesyesyesyes
bcmathyesyesyesyes
bz2yesyesyesyes
calendaryesyesyesyes
ctypeyesyesyesyes
curlyesyesyesyes
dbayesyesyesyes
domyesyesyes
dsyesyesyesyes
enchant
eventyesyes
exifyesyesyesyes
ffinoyesyes
fileinfoyesyesyesyes
filteryesyesyesyes
ftpyesyesyesyes
gdyesyesyes
gettextyesyes
glfwnoyesno
gmpyesyes
iconvyesyesyes
igbinaryyesyes
imagickyesyes
imapyesyes
inotifyyesnono
intlyesyesno
ldapyesyes
libxmlyesyesyes
mbregexyesyesyesyes
mbstringyesyesyesyes
mcryptnononono
memcacheyesyes
memcachednoyes
mongodbyesyes
mysqliyesyesyesyes
mysqlndyesyesyesyes
oci8nonono
opcacheyesyesyesyes
opensslyesyesyesyes
parallelyesyesyes
password-argon2yesyes
pcntlyesyesyesno
pdoyesyesyesyes
pdo_mysqlyesyesyesyes
pdo_pgsqlyesyes
pdo_sqliteyesyesyes
pdo_sqlsrvyesyesyes
pgsqlyesyes
pharyesyesyesyes
posixyesyesyesno
protobufyesyes
raryespartialyes
readlineyesyes
redisyesyes
sessionyesyesyesyes
shmopyesyesyesyes
simdjsonyesyesyesyes
simplexmlyesyesyes
snappyyesyes
soapyesyesyes
socketsyesyesyesyes
sodiumyesyes
sqlite3yesyesyes
sqlsrvyesyesyes
ssh2yesyesyes
swooleyesyesno
swoole-hook-mysqlyesyesno
swoole-hook-pgsqlyespartialno
swoole-hook-sqliteyesyesno
swowyesyesyes
sysvmsgyesyesno
sysvsemyesyesno
sysvshmyesyesyes
tidyyesyes
tokenizeryesyesyesyes
uuidyesyes
uvyesyes
xdebugnonono
xhprofyesyes
xlswriteryesyes
xmlyesyesyes
xmlreaderyesyesyes
xmlwriteryesyesyes
xslyesyes
yacyesyesyes
yamlyesyesyes
zipyesyesyes
zlibyesyesyesyes
zstdyesyes

TIP

If an extension you need is missing, you can create a Feature Request.

Some extensions or libraries that the extension depends on will have some optional features. For example, the gd library optionally supports libwebp, freetype, etc. If you only use bin/spc build gd --build-cli they will not be included (static-php-cli defaults to the minimum dependency principle).

You can use --with-libs= to add these libraries when compiling. When the dependent libraries of this compilation include them, gd will automatically use them to enable these features. (For example: bin/spc build gd --with-libs=libwebp,freetype --build-cli)

Alternatively you can use --with-suggested-exts and --with-suggested-libs to enable all optional dependencies of these extensions and libraries. (For example: bin/spc build gd --with-suggested-libs --build-cli)

If you don't know whether an extension has optional features, you can check the spc configuration file or use the command bin/spc dev:extensions (library dependency is lib-suggests, extension dependency is ext-suggests).

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/guide/index.html b/en/guide/index.html index f2e799c5..ce897af4 100644 --- a/en/guide/index.html +++ b/en/guide/index.html @@ -18,7 +18,7 @@
Skip to content

Guide

Static php cli is a tool used to build statically compiled PHP binaries, currently supporting Linux and macOS systems.

In the guide section, you will learn how to use static php cli to build standalone PHP programs.

TIP

If you are a native English speaker, some corrections to the documentation are welcome. (Docs repo)

Compilation Environment

The following is the architecture support situation, where ⚙️ represents support for GitHub Action build, 💻 represents support for local manual build, and empty represents temporarily not supported.

x86_64aarch64
macOS⚙️ 💻⚙️ 💻
Linux⚙️ 💻⚙️ 💻
Windows⚙️ 💻
FreeBSD💻💻

Among them, Linux is currently only tested on Ubuntu, Debian, and Alpine distributions, and other distributions have not been tested, which cannot guarantee successful compilation. For untested distributions, local compilation can be done using methods such as Docker to avoid environmental issues.

There are two architectures for macOS: x86_64 and Arm, but binaries compiled on one architecture cannot be directly used on the other architecture. Rosetta 2 cannot guarantee that programs compiled with Arm architecture can fully run on x86_64 environment.

Windows currently only supports the x86_64 architecture, and does not support 32-bit x86 or arm64 architecture.

Supported PHP Version

Currently, static php cli supports PHP versions 8.0 to 8.3, and theoretically supports PHP 7.4 and earlier versions. Simply select the earlier version when downloading. However, due to some extensions and special components that have stopped supporting earlier versions of PHP, static-php-cli will not explicitly support earlier versions. We recommend that you compile the latest PHP version possible for a better experience.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/guide/manual-build.html b/en/guide/manual-build.html index 4e22c67d..c3b5afbd 100644 --- a/en/guide/manual-build.html +++ b/en/guide/manual-build.html @@ -156,7 +156,7 @@ $ buildroot/bin/php -i | grep memory memory_limit => 8G => 8G

For the objects, methods and interfaces supported by static-php-cli, you can read the source code. Most methods and objects have corresponding comments.

Commonly used objects and functions using the -P function are:

TIP

static-php-cli has many open methods, which cannot be listed in the docs, but as long as it is a public function and is not marked as @internal, it theoretically can be called.

- + \ No newline at end of file diff --git a/en/guide/troubleshooting.html b/en/guide/troubleshooting.html index a80dd4ae..0acd2864 100644 --- a/en/guide/troubleshooting.html +++ b/en/guide/troubleshooting.html @@ -18,7 +18,7 @@
Skip to content

Troubleshooting

Various failures may be encountered in the process of using static-php-cli, here will describe how to check the errors by yourself and report Issue.

Download Failure

Problems with downloading resources are one of the most common problems with spc. The main reason is that the addresses used for SPC download resources are generally the official website of the corresponding project or GitHub, etc., and these websites may occasionally go down and block IP addresses. Currently, version 2.0.0 has not added an automatic retry mechanism, so after encountering a download failure, you can try to call the download command multiple times. If you confirm that the address is indeed inaccessible, you can submit an Issue or PR to update the url or download type.

Doctor Can't Fix Something

In most cases, the doctor module can automatically repair and install missing system environments, but there are also special circumstances where the automatic repair function cannot be used normally.

Due to system limitations (for example, software such as Visual Studio cannot be automatically installed under Windows), the automatic repair function cannot be used for some projects. When encountering a function that cannot be automatically repaired, if you encounter the words Some check items can not be fixed, it means that it cannot be automatically repaired. Please submit an issue according to the method displayed on the terminal or repair the environment yourself.

Compile Error

When you encounter a compilation error, if the --debug log is not enabled, please enable the debug log first, and then determine the command that reported the error. The error terminal output is very important for fixing compilation errors. When submitting an issue, please upload the last error fragment of the terminal log (or the entire terminal log output), and include the spc command and parameters used.

Released under the MIT License.

- + \ No newline at end of file diff --git a/en/index.html b/en/index.html index 53eadb02..c96e90f0 100644 --- a/en/index.html +++ b/en/index.html @@ -18,7 +18,7 @@
Skip to content

static-php-cli

Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included.

Released under the MIT License.

- + \ No newline at end of file diff --git a/extension-notes.html b/extension-notes.html index d183aae8..876e9921 100644 --- a/extension-notes.html +++ b/extension-notes.html @@ -18,7 +18,7 @@
Skip to content
- + \ No newline at end of file diff --git a/extensions.html b/extensions.html index acd2de6e..677d3cb6 100644 --- a/extensions.html +++ b/extensions.html @@ -18,7 +18,7 @@
Skip to content
Extension NameLinuxmacOSFreeBSDWindows
amqpyesyesyes
apcuyesyesyesyes
bcmathyesyesyesyes
bz2yesyesyesyes
calendaryesyesyesyes
ctypeyesyesyesyes
curlyesyesyesyes
dbayesyesyesyes
domyesyesyes
dsyesyesyesyes
enchant
eventyesyes
exifyesyesyesyes
ffinoyesyes
fileinfoyesyesyesyes
filteryesyesyesyes
ftpyesyesyesyes
gdyesyesyes
gettextyesyes
glfwnoyesno
gmpyesyes
iconvyesyesyes
igbinaryyesyes
imagickyesyes
imapyesyes
inotifyyesnono
intlyesyesno
ldapyesyes
libxmlyesyesyes
mbregexyesyesyesyes
mbstringyesyesyesyes
mcryptnononono
memcacheyesyes
memcachednoyes
mongodbyesyes
mysqliyesyesyesyes
mysqlndyesyesyesyes
oci8nonono
opcacheyesyesyesyes
opensslyesyesyesyes
parallelyesyesyes
password-argon2yesyes
pcntlyesyesyesno
pdoyesyesyesyes
pdo_mysqlyesyesyesyes
pdo_pgsqlyesyes
pdo_sqliteyesyesyes
pdo_sqlsrvyesyesyes
pgsqlyesyes
pharyesyesyesyes
posixyesyesyesno
protobufyesyes
raryespartialyes
readlineyesyes
redisyesyes
sessionyesyesyesyes
shmopyesyesyesyes
simdjsonyesyesyesyes
simplexmlyesyesyes
snappyyesyes
soapyesyesyes
socketsyesyesyesyes
sodiumyesyes
sqlite3yesyesyes
sqlsrvyesyesyes
ssh2yesyesyes
swooleyesyesno
swoole-hook-mysqlyesyesno
swoole-hook-pgsqlyespartialno
swoole-hook-sqliteyesyesno
swowyesyesyes
sysvmsgyesyesno
sysvsemyesyesno
sysvshmyesyesyes
tidyyesyes
tokenizeryesyesyesyes
uuidyesyes
uvyesyes
xdebugnonono
xhprofyesyes
xlswriteryesyes
xmlyesyesyes
xmlreaderyesyesyes
xmlwriteryesyesyes
xslyesyes
yacyesyesyes
yamlyesyesyes
zipyesyesyes
zlibyesyesyesyes
zstdyesyes
- + \ No newline at end of file diff --git a/hashmap.json b/hashmap.json index 671064a5..9a463963 100644 --- a/hashmap.json +++ b/hashmap.json @@ -1 +1 @@ -{"en_contributing_index.md":"DZraZA7y","en_develop_system-build-tools.md":"CEtH7ZDM","en_develop_structure.md":"DV_1s770","en_guide_env-vars.md":"uwjapWk-","en_guide_extension-notes.md":"nR2uVBsd","en_guide_cli-generator.md":"ug50c3ht","en_guide_index.md":"BHNXifuG","en_guide_build-on-windows.md":"BfWaQWNz","en_guide_extensions.md":"BI8yDIvH","en_index.md":"BUfMQ6rb","extensions.md":"CL2tFs7q","en_guide_troubleshooting.md":"SCdTjpCB","zh_guide_extension-notes.md":"DlxOQhU8","zh_faq_index.md":"DzybCGmE","en_develop_index.md":"DpXFrPSW","en_develop_doctor-module.md":"DC_o8-Ms","en_develop_source-module.md":"rpNWeksK","zh_develop_source-module.md":"p7qFI6uL","zh_guide_cli-generator.md":"Br2RArL0","zh_develop_system-build-tools.md":"BcSEvLWq","zh_develop_doctor-module.md":"1zI3NHLP","zh_develop_structure.md":"BKo1eXYT","zh_guide_extensions.md":"BqQUcrN1","zh_contributing_index.md":"COUOrvr5","index.md":"D-mm_nya","zh_develop_index.md":"DjGoZ0WL","extension-notes.md":"jzIo6LDw","en_guide_manual-build.md":"DMcOJniP","zh_guide_troubleshooting.md":"Bqj2SVrP","en_faq_index.md":"BVyZnjBj","zh_guide_manual-build.md":"BGuYiUSe","zh_guide_action-build.md":"BdoXFRC0","zh_guide_build-on-windows.md":"CA6k7NVv","zh_index.md":"DpfrTEU3","en_guide_action-build.md":"D4sK_4FO","zh_guide_index.md":"B-3jYE0-","zh_guide_env-vars.md":"BtevEgOs"} +{"zh_guide_cli-generator.md":"Br2RArL0","zh_guide_extensions.md":"BqQUcrN1","en_guide_extensions.md":"BI8yDIvH","zh_faq_index.md":"DzybCGmE","en_guide_action-build.md":"D4sK_4FO","zh_develop_system-build-tools.md":"BcSEvLWq","zh_index.md":"DpfrTEU3","en_develop_source-module.md":"rpNWeksK","zh_guide_env-vars.md":"BtevEgOs","en_guide_extension-notes.md":"nR2uVBsd","en_develop_index.md":"DpXFrPSW","en_develop_structure.md":"DV_1s770","en_guide_index.md":"BHNXifuG","zh_develop_doctor-module.md":"1zI3NHLP","en_guide_troubleshooting.md":"SCdTjpCB","en_faq_index.md":"BVyZnjBj","zh_contributing_index.md":"COUOrvr5","zh_guide_troubleshooting.md":"Bqj2SVrP","index.md":"D-mm_nya","en_develop_system-build-tools.md":"CEtH7ZDM","extensions.md":"CL2tFs7q","en_index.md":"BUfMQ6rb","extension-notes.md":"jzIo6LDw","zh_guide_manual-build.md":"BGuYiUSe","en_guide_build-on-windows.md":"BfWaQWNz","zh_guide_build-on-windows.md":"CA6k7NVv","en_guide_cli-generator.md":"ug50c3ht","zh_develop_index.md":"DjGoZ0WL","zh_guide_action-build.md":"BdoXFRC0","en_contributing_index.md":"DZraZA7y","en_guide_env-vars.md":"uwjapWk-","en_develop_doctor-module.md":"DC_o8-Ms","zh_guide_index.md":"B-3jYE0-","en_guide_manual-build.md":"DMcOJniP","zh_guide_extension-notes.md":"DlxOQhU8","zh_develop_source-module.md":"p7qFI6uL","zh_develop_structure.md":"BKo1eXYT"} diff --git a/index.html b/index.html index 27e8db79..4bf60b6c 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@
Skip to content

static-php-cli

Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included.

- + \ No newline at end of file diff --git a/zh/contributing/index.html b/zh/contributing/index.html index 18915a9b..21269d17 100644 --- a/zh/contributing/index.html +++ b/zh/contributing/index.html @@ -18,7 +18,7 @@
Skip to content

贡献指南

感谢你能够看到这里,本项目非常欢迎你的贡献!

贡献方法

如果你有代码或文档想要贡献,需要先了解以下内容。

  1. 你要贡献什么类型的代码?(新扩展、修复 Bug、安全问题、项目框架优化、文档)
  2. 如果你贡献了新文件或新片段,你的代码是否经过 php-cs-fixerphpstan 的检查?
  3. 在贡献代码前是否充分阅读了 开发指南

如果你可以回答以上问题,并已经对代码做出了修改,可以及时在项目 GitHub 仓库发起 Pull Request。待代码审查完毕后,可根据建议修改代码,或直接合并到主分支。

贡献类型

本项目主要用途是编译静态链接的 PHP 二进制,基于 symfony/console 编写了命令行处理功能。在开发之前,如果你对它不够熟悉, 可以先查看 symfony/console 文档

安全问题

因为本项目基本上是属于本地运行的 PHP 项目,一般来说不会存在远程攻击行为。但如果你发现了此类问题,请不要在 GitHub 仓库提交 PR 或 Issue, 你需要通过 邮件 的方式联系项目维护者(crazywhalecc)。

修复 Bug

修复 Bug 一般不涉及项目结构和框架的修改,所以如果你可以定位到错误代码并直接修复它,请直接提交 PR。

新扩展

对于添加一个新扩展来说,你需要先了解一些本项目的基本结构,以及如何根据现有的逻辑添加新扩展。在本页的下一章节将会详细介绍。 总的来说,你需要:

  1. 评估扩展是否可以内联编译到 PHP 中。
  2. 评估扩展的依赖库(如果有)是否可以静态编译。
  3. 写出扩展的依赖库在不同平台编译命令。
  4. 验证扩展及其依赖库能否与现有扩展和依赖库兼容。
  5. 验证扩展在 climicrofpmembed 几种 SAPI 中均正常工作。
  6. 编写文档,加入你的扩展。

项目框架优化

如果你已经熟悉 symfony/console 的工作原理,并同时要对项目的框架进行一些修改或优化,请先了解以下事情:

  1. 加入扩展不属于项目框架优化,但如果你在加入新的扩展时发现不得不优化框架,则需先对框架本身进行修改,然后再加入扩展。
  2. 对于一些大规模逻辑修改(例如涉及 LibraryBase、Extension 对象等的修改)时,建议先提交 Issue 或 Draft PR 进行讨论方案。
  3. 项目早期为纯中文开发项目,代码中存在一部分中文的注释。国际化项目后你可以提交 PR 将这些注释翻译为英语。
  4. 请不要在代码中提交包含较多无用的代码片段,例如大量未被使用的变量、方法、类、重复写了很多次的代码。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/develop/doctor-module.html b/zh/develop/doctor-module.html index 29a17d8d..928e9b99 100644 --- a/zh/develop/doctor-module.html +++ b/zh/develop/doctor-module.html @@ -46,7 +46,7 @@ } return true; }

#[AsFixItem()] 属性传入的参数即修复项的名称,该方法必须返回 True 或 False。当返回 False 时,表明自动修复失败,需要手动处理。

此处的代码中 shell()->exec() 是项目的执行命令的方法,用于替代 exec()system(),同时提供了 debug、获取执行状态、进入目录等特性。

- + \ No newline at end of file diff --git a/zh/develop/index.html b/zh/develop/index.html index fdff40ad..6bc89138 100644 --- a/zh/develop/index.html +++ b/zh/develop/index.html @@ -18,7 +18,7 @@
Skip to content

开发简介

开发本项目需要安装部署 PHP 环境,以及一些 PHP 项目常用的扩展和 Composer。

项目的开发环境和运行环境几乎完全一致,你可以参照 指南-本地构建 部分安装系统 PHP 或使用本项目预构建的静态 PHP 作为环境,这里不再赘述。

抛开用途,本项目本身其实就是一个 php-cli 程序,你可以将它当作一个正常的 PHP 项目进行编辑和开发,同时你需要了解不同系统的 Shell 命令行。

本项目目前的目的就是为了编译静态编译的独立 PHP,但主体部分也包含编译很多依赖库的静态版本,所以你可以复用这套编译逻辑,用于构建其他程序的独立二进制版本,例如 Nginx 等。

环境准备

开发本项目需要 PHP 环境。你可以使用系统自带的 PHP,也可以使用本项目构建的静态 PHP。

无论是使用哪种 PHP,在开发环境,你需要安装这些扩展:

curl,dom,filter,mbstring,openssl,pcntl,phar,posix,sodium,tokenizer,xml,xmlwriter

static-php-cli 项目本身不需要这么多扩展,但在开发过程中,你会用到 Composer、PHPUnit 等工具,它们需要这些扩展。

对于 static-php-cli 自身构建的 micro 自执行二进制,仅需要 pcntl,posix,mbstring,tokenizer,phar

开始开发

继续向下查看项目结构的文档,你可以从中了解 static-php-cli 是如何运作的。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/develop/source-module.html b/zh/develop/source-module.html index b5a6303b..f131455a 100644 --- a/zh/develop/source-module.html +++ b/zh/develop/source-module.html @@ -122,7 +122,7 @@ ] } } - + \ No newline at end of file diff --git a/zh/develop/structure.html b/zh/develop/structure.html index 11cd3232..1247c9c1 100644 --- a/zh/develop/structure.html +++ b/zh/develop/structure.html @@ -27,7 +27,7 @@ box.json # 打包 Phar 的配置文件 another-app.php # 另一个项目的入口文件 vendor/crazywhalecc/static-php-cli/* # 你的项目被作为依赖库

将该目录 /home/example/another-app/ 下的这些文件打包为 app.phar 时,对于你的项目而言,下面常量的值应为:

ConstantValue
WORKING_DIR/home/example/another-app
SOURCE_ROOT_DIRphar:///home/example/another-app/app.phar/
FRAMEWORK_ROOT_DIRphar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli
__DIR__phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App
__FILE__phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App/MyCommand.php
- + \ No newline at end of file diff --git a/zh/develop/system-build-tools.html b/zh/develop/system-build-tools.html index 3d2c96fb..4bd60880 100644 --- a/zh/develop/system-build-tools.html +++ b/zh/develop/system-build-tools.html @@ -84,7 +84,7 @@ make TARGET=x86_64-linux-musl -j make TARGET=x86_64-linux-musl install -j tar cvzf x86_64-musl-toolchain.tgz output/*

TIP

以上所有脚本都适用于 x86_64 架构的 Linux。如果你需要构建 ARM 环境的 musl-cross-make,只需要将上方所有 x86_64 替换为 aarch64 即可。

这个编译过程可能会因为内存不足、网络问题等原因导致编译失败,你可以多尝试几次,或者使用更大内存的机器来编译。 如果遇到了问题,或者你有更好的改进方案,可以在 讨论 中提出。

macOS 环境编译工具

对于 macOS 系统来说,我们使用的编译工具主要是 clang,它是 macOS 系统默认的编译器,同时也是 Xcode 的编译器。

在 macOS 下编译,主要依赖于 Xcode 或 Xcode Command Line Tools,你可以在 App Store 下载 Xcode,或者在终端执行 xcode-select --install 来安装 Xcode Command Line Tools。

此外,在 doctor 环境检查模块中,static-php-cli 会检查 macOS 系统是否安装了 Homebrew、编译工具等,如果没有,会提示你安装,这里不再赘述。

FreeBSD 环境编译工具

FreeBSD 也是 Unix 系统,它的编译工具和 macOS 类似,你可以直接使用包管理 pkg 安装 clang 等编译工具,通过 doctor 命令。

pkg-config 编译

如果你在使用 static-php-cli 构建静态 PHP 时仔细观察编译的日志,你会发现无论编译什么,都会先编译 pkg-config,这是因为 pkg-config 是一个用于查找依赖库的工具。 在早期的 static-php-cli 版本中,我们直接使用了包管理安装的 pkg-config 工具,但是这样会导致一些问题,例如:

为了避免以上问题,我们将 pkg-config 编译到用户态的 buildroot/bin 内并使用,使用了 --without-sysroot 等参数来避免从系统路径中查找依赖包。

- + \ No newline at end of file diff --git a/zh/faq/index.html b/zh/faq/index.html index 6279a2bf..4f97d492 100644 --- a/zh/faq/index.html +++ b/zh/faq/index.html @@ -19,7 +19,7 @@
Skip to content

常见问题

这里将会编写一些你容易遇到的问题。目前有很多,但是我需要花时间来整理一下。

静态编译的 PHP 可以安装扩展吗

因为传统架构下的 PHP 安装扩展的原理是使用 .so 类型的动态链接的库方式安装新扩展,而使用本项目编译的静态链接的 PHP 无法直接使用动态链接库安装新扩展。

对于 macOS 平台来说,macOS 下的几乎所有二进制文件都无法真正纯静态链接,几乎所有二进制文件都会链接 macOS 的系统库:/usr/lib/libresolv.9.dylib/usr/lib/libSystem.B.dylib。 所以在 macOS 系统下,在特定的编译条件下可以使用静态编译的 php 二进制文件,同时使用动态链接的扩展:

  1. 使用 --no-strip 参数,将不会对二进制文件去除调试符号等信息,以供使用 Xdebug 等外部 Zend 扩展。
  2. 如果要编译某些 Zend 扩展,使用 Homebrew、MacPorts、源码编译的形式,在所在的操作系统安装一个普通版本的 PHP。
  3. 使用 phpize && ./configure && make 命令编译想要使用的扩展。
  4. 将扩展文件 xxxx.so 拷贝到外部,使用静态编译的 PHP 二进制,例如使用 Xdebug 扩展:cd buildroot/bin/ && ./php -d "zend_extension=/path/to/xdebug.so"
bash
# 构建静态 php-cli
 bin/spc build ffi --build-cli --no-strip

对于 Linux 平台来说,目前的编译结果为纯静态链接的二进制文件,无法使用动态链接库安装新扩展。

可以支持 Oracle 数据库扩展吗

部分依赖库闭源的扩展,如 oci8sourceguardian 等,它们没有提供纯静态编译的依赖库文件(.a),仅提供了动态依赖库文件(.so), 这些扩展无法使用源码的形式编译到 static-php-cli 中,所以本项目可能永远也不会支持这些扩展。不过,理论上你可以根据上面的问题在 macOS 下接入和使用这类扩展。

如果你对此类扩展有需求,或者大部分人都对这些闭源扩展使用有需求, 可以看看有关 standalone-php-cli 的讨论。欢迎留言。

支持 Windows 吗

该项目目前已支持 Windows,但支持的扩展数量较少,Windows 的支持并不完美,主要有以下几个问题:

  1. Windows 的编译流程与 *nix 不同,使用的工具链也不同,编译各个扩展的依赖库使用的编译工具也几乎完全不同。
  2. Windows 版本的需求也会根据所有使用本项目的人的需求推进,如果有很多人需要,我会尽快支持相关扩展。

使用 micro 可以保护我的源码吗

不可以。micro.sfx 本质上是将 php 和 php 代码结合为一个文件,没有 PHP 代码编译或加密的过程。 首先 php-src 是 PHP 代码的官方解释器,而且现在市面上还没有一个能兼容主流分支的 PHP 编译器。 之前我在网上看到有一个项目是 BPC(Binary PHP Compiler?)可以把 PHP 编译为二进制,但是限制也是很多很多。

加密保护代码的方向和编译也不是一回事,编译过后也可以通过逆向工程等方式拿到代码,真正保护还是通过加壳、加密代码等手段进行。

所以本项目(static-php-cli)、相关项目(lwmbs、swoole-cli)都是提供一个对 php-src 源码的便捷编译工具, 本项目和相关项目引用的 phpmicro 也仅仅是 PHP 的 sapi 接口封装,而不是 PHP 代码的编译工具。 PHP 代码的编译器是完全不同的项目,因此不会考虑额外的情况。如果你对加密感兴趣,可以考虑使用现有的加密技术,如 Swoole Compiler、Source Guardian 等。

无法使用 ssl

使用 curl、pgsql 等 请求 HTTPS 网站或建立 SSL 连接时,可能存在 error:80000002:system library::No such file or directory 错误, 这个错误是由于静态编译的 PHP 未通过 php.ini 指定 openssl.cafile 导致的。

你可以在使用 PHP 前指定 php.ini,并在 INI 内添加 openssl.cafile=/path/to/your-cert.pem 来解决这个问题。

对于 Linux 系统,你可以从 curl 官方网站下载 cacert.pem 文件,也可以使用系统自带的证书文件。 有关不同发行版的证书位置,可参考 Go 标准库

INI 配置 openssl.cafile 不可以使用 ini_set() 函数动态设置,因为 openssl.cafile 是一个 PHP_INI_SYSTEM 类型的配置,只能在 php.ini 文件中设置。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/guide/action-build.html b/zh/guide/action-build.html index 31fc2ed3..5466910a 100644 --- a/zh/guide/action-build.html +++ b/zh/guide/action-build.html @@ -18,7 +18,7 @@
Skip to content

Action 构建

Action 构建指的是直接使用 GitHub Action 进行编译。

如果你不想自行编译,可以从本项目现有的 Action 下载 Artifact,也可以从自托管的服务器下载:进入

自托管的二进制也是由 Action 构建而来,项目仓库地址

构建方法

使用 GitHub Action 可以方便地构建一个静态编译的 PHP 和 phpmicro,同时可以自行定义要编译的扩展。

  1. Fork 本项目。
  2. 进入项目的 Actions,选择 CI 开头的 Workflow(根据你需要的操作系统选择)。
  3. 选择 Run workflow,填入你要编译的 PHP 版本、目标类型、扩展列表。(扩展列表使用英文逗号分割,例如 bcmath,curl,mbstring
  4. 等待大约一段时间后,进入对应的任务中,获取 Artifacts

如果你选择了 debug,则会在构建时输出所有日志,包括编译的日志,以供排查错误。

如果你需要在其他环境构建,可以使用 手动构建

扩展选择

你可以到 扩展列表 中查看目前你需要的扩展是否均支持, 然后到 在线命令生成 中选择你需要编译的扩展,复制扩展字符串到 Action 的 extensions 中,编译即可。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/guide/build-on-windows.html b/zh/guide/build-on-windows.html index 117b30ed..74e8f02e 100644 --- a/zh/guide/build-on-windows.html +++ b/zh/guide/build-on-windows.html @@ -39,7 +39,7 @@ bin/spc micro:combine code.php -O my-app.exe # Run it!!! Copy it to another computer!!! ./my-app.exe

如果打包 PHAR 文件,仅需把 code.php 更换为 phar 文件路径即可。 你可以使用 box-project/box 将你的 CLI 项目打包为 Phar, 然后将它与 phpmicro 结合,生成独立可执行的二进制文件。

有关 micro:combine 命令的更多细节,请参考 Unix 系统上的 命令

- + \ No newline at end of file diff --git a/zh/guide/cli-generator.html b/zh/guide/cli-generator.html index d9f993f8..ca7b918d 100644 --- a/zh/guide/cli-generator.html +++ b/zh/guide/cli-generator.html @@ -19,7 +19,7 @@
Skip to content

CLI 编译命令生成器

TIP

下面选择扩展可能包含所选操作系统不支持的扩展,这可能导致编译失败。请先查阅 支持的扩展

选择操作系统

选择扩展

选择常用扩展
全部取消选择
要构建的库

TIP

选择扩展后,不可选中的项目为必需的依赖,编译的依赖库列表中可选的为现有扩展和依赖库的可选依赖。选择可选依赖后,将生成 --with-libs 参数。

选择编译目标

编译选项

编译环境
下载 PHP 版本
是否开启调试输出
是否编译线程安全版
是否展示仅下载对应扩展依赖的命令
是否开启 UPX 压缩(减小二进制体积,但很少见的情况下 micro SAPI 无法使用)

硬编码 INI 选项

结果展示

只下载对应扩展的依赖包命令
bin/spc download --with-php=8.2 --for-extensions ""
编译命令
bin/spc build --build-cli ""

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/guide/env-vars.html b/zh/guide/env-vars.html index 7971fcb2..1a34771d 100644 --- a/zh/guide/env-vars.html +++ b/zh/guide/env-vars.html @@ -23,7 +23,7 @@ # 直接设置方式 SPC_CONCURRENCY=4 bin/spc build mbstring,pcntl --build-cli

通用环境变量

通用环境变量是所有构建目标都可以使用的环境变量。

var namedefault valuecomment
BUILD_ROOT_PATH{pwd}/buildroot编译目标的根目录
BUILD_LIB_PATH{pwd}/buildroot/lib编译依赖库的根目录
BUILD_INCLUDE_PATH{pwd}/buildroot/include编译依赖库的头文件目录
BUILD_BIN_PATH{pwd}/buildroot/bin编译依赖库的二进制文件目录
PKG_ROOT_PATH{pwd}/pkgroot闭源或预编译工具下载后安装的目录
SOURCE_PATH{pwd}/source编译项目的源码解压缩目录
DOWNLOAD_PATH{pwd}/downloads下载的文件存放目录
SPC_CONCURRENCY取决于当前 CPU 核心数量并行编译的数量
SPC_SKIP_PHP_VERSION_CHECK设置为 yes 时,跳过扩展对 PHP 版本的检查

系统特定变量

这些环境变量是特定于系统的,它们只在特定的系统上才会生效。

Windows

var namedefault valuecomment
PHP_SDK_PATH{pwd}\php-sdk-binary-toolsPHP SDK 工具的安装目录
UPX_EXEC$PKG_ROOT_PATH\bin\upx.exeUPX 压缩工具的路径

macOS

var namedefault valuecomment
CCclangC 编译器
CXXclang++C++ 编译器
SPC_DEFAULT_C_FLAGS--target=arm64-apple-darwin--target=x86_64-apple-darwin默认 C 编译标志(与 CFLAGS 不同)
SPC_DEFAULT_CXX_FLAGS--target=arm64-apple-darwin--target=x86_64-apple-darwin默认 C++ 编译标志(与 CXXFLAGS 不同)
SPC_CMD_PREFIX_PHP_BUILDCONF./buildconf --force编译 PHP buildconf 命令前缀
SPC_CMD_PREFIX_PHP_CONFIGURE./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg编译 PHP configure 命令前缀
SPC_CMD_PREFIX_PHP_MAKEmake -j$SPC_CONCURRENCY编译 PHP make 命令前缀
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS$SPC_DEFAULT_C_FLAGS -Werror=unknown-warning-optionPHP configure 命令的 CFLAGS 变量
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS-I$BUILD_INCLUDE_PATHPHP configure 命令的 CPPFLAGS 变量
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS-L$BUILD_LIB_PATHPHP configure 命令的 LDFLAGS 变量
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS-g0 -Os-g -O0(当使用 --no-strip 时为后者)PHP make 命令的 EXTRA_CFLAGS 变量
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS-lresolvPHP make 命令的额外 EXTRA_LIBS 变量

Linux

var namedefault valuecomment
UPX_EXEC$PKG_ROOT_PATH/bin/upxUPX 压缩工具的路径
GNU_ARCHx86_64aarch64当前环境的 CPU 架构
CCAlpine: gcc, Other: $GNU_ARCH-linux-musl-gccC 编译器
CXXAlpine: g++, Other: $GNU_ARCH-linux-musl-g++C++ 编译器
ARAlpine: ar, Other: $GNU_ARCH-linux-musl-ar静态库工具
LDld.gold链接器
PATH/usr/local/musl/bin:/usr/local/musl/$GNU_ARCH-linux-musl/bin:$PATH系统 PATH
SPC_DEFAULT_C_FLAGSempty默认 C 编译标志
SPC_DEFAULT_CXX_FLAGSempty默认 C++ 编译标志
SPC_CMD_PREFIX_PHP_BUILDCONF./buildconf --force编译 PHP buildconf 命令前缀
SPC_CMD_PREFIX_PHP_CONFIGURELD_LIBRARY_PATH={ld_lib_path} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg编译 PHP configure 命令前缀
SPC_CMD_PREFIX_PHP_MAKEmake -j$SPC_CONCURRENCY编译 PHP make 命令前缀
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS$SPC_DEFAULT_C_FLAGSPHP configure 命令的 CFLAGS 变量
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS-I$BUILD_INCLUDE_PATHPHP configure 命令的 CPPFLAGS 变量
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS-L$BUILD_LIB_PATHPHP configure 命令的 LDFLAGS 变量
SPC_CMD_VAR_PHP_CONFIGURE_LIBS-ldl -lpthreadPHP configure 命令的 LIBS 变量
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS-g0 -Os -fno-ident -fPIE-g -O0 -fno-ident -fPIE(当使用 --no-strip 时为后者)PHP make 命令的 EXTRA_CFLAGS 变量
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBSemptyPHP make 命令的额外 EXTRA_LIBS 变量
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM-all-static(当使用 clang 时:-Xcompiler -fuse-ld=lld -all-staticmake 命令的额外 LDFLAGS 变量(用于编译程序)
SPC_NO_MUSL_PATHempty是否不插入 musl 工具链的 PATH(值为 yes 时不插入)

{ld_lib_path} 值为 /usr/local/musl/$GNU_ARCH-linux-musl/lib

FreeBSD

因 FreeBSD 系统的用户较少,我们暂时不提供 FreeBSD 系统的环境变量。

Unix

对于 macOS、Linux、FreeBSD 等 Unix 系统,以下环境变量是通用的。

var namedefault valuecomment
PATH$BUILD_BIN_PATH:$PATH系统 PATH
PKG_CONFIG_PATH$BUILD_LIB_PATH/pkgconfigpkg-config 的搜索路径
PKG_CONFIG$BUILD_BIN_PATH/pkg-configpkg-config 命令路径

编译依赖库的环境变量(仅限 Unix 系统)

从 2.2.0 开始,static-php-cli 对所有 macOS、Linux、FreeBSD 等 Unix 系统的编译依赖库的命令均支持自定义环境变量。

这样你就可以随时通过环境变量来调整编译依赖库的行为。例如你可以通过 xxx_CFLAGS=-O0 来设置编译 xxx 库的优化参数。

当然,不是每个依赖库都支持注入环境变量,我们目前提供了三个通配的环境变量,后缀分别为:

前缀为依赖库的名称,具体依赖库的名称以 lib.json 为准。其中,带有 - 的依赖库名称需要将 - 替换为 _

下面是一个替换 openssl 库编译的优化选项示例:

shell
openssl_CFLAGS="-O0"

库名称使用同 lib.json 中列举的名称,区分大小写。

TIP

当未指定相关环境变量时,除以下变量外,其余值均默认为空:

var namevar default value
pkg_config_CFLAGSmacOS: $SPC_DEFAULT_C_FLAGS -Wimplicit-function-declaration -Wno-int-conversion, Other: empty
pkg_config_LDFLAGSLinux: --static, Other: empty
imagemagick_LDFLAGSLinux: -static, Other: empty
imagemagick_LIBSmacOS: -liconv, Other: empty
ldap_LDFLAGS-L$BUILD_LIB_PATH
openssl_CFLAGSLinux: $SPC_DEFAULT_C_FLAGS, Other: empty
others...empty

下表是支持自定义以上三种变量的依赖库名称列表:

lib name
brotli
bzip
curl
freetype
gettext
gmp
imagemagick
ldap
libargon2
libavif
libcares
libevent
openssl

TIP

因为给每个库适配自定义环境变量是一项特别繁琐的工作,且大部分情况下你都不需要这些库的自定义环境变量,所以我们目前只支持了部分库的自定义环境变量。

如果你需要自定义环境变量的库不在上方列表,可以通过 GitHub Issue 来提出需求。

- + \ No newline at end of file diff --git a/zh/guide/extension-notes.html b/zh/guide/extension-notes.html index b65e701f..7f291c3c 100644 --- a/zh/guide/extension-notes.html +++ b/zh/guide/extension-notes.html @@ -18,7 +18,7 @@
Skip to content

扩展注意事项

因为是静态编译,扩展不会 100% 完美编译,而且不同扩展对 PHP、环境都有不同的要求,这里将一一列举。

curl

使用 curl 请求 HTTPS 时,可能存在 error:80000002:system library::No such file or directory 错误, 解决办法详见 FAQ - 无法使用 ssl

phpmicro

  1. phpmicro SAPI 仅支持 PHP >= 8.0 版本。

swoole

  1. swoole >= 5.0 版本仅支持 PHP >= 8.0 版本。
  2. swoole 目前不支持 PHP 8.0 版本 curl 的 hook(后续有可能会修复)。
  3. 编译时只包含 swoole 扩展时不会完整开启支持的 Swoole 数据库协程 hook,如需使用请加入对应的 swoole-hook-xxx 扩展。
  4. swoole 在部分扩展组合下可能出现 zend_mm_heap corrupted 问题,暂未找到是什么原因导致的。

swoole-hook-pgsql

swoole-hook-pgsql 不是一个扩展,而是 Swoole 的 Hook 特性。 如果你在编译时添加了 swoole,swoole-hook-pgsql,你将启用 Swoole 的 PostgreSQL 客户端和 pdo_pgsql 扩展的协程模式。

swoole-hook-pgsql 与 pdo_pgsql 扩展冲突。如需使用 Swoole 和 pdo_pgsql,请删除 pdo_pgsql 扩展,启用 swooleswoole-hook-pgsql 即可。 该扩展包含了 pdo_pgsql 的协程环境的实现。

在 macOS 系统,pdo_pgsql 可能无法正常连接到 postgresql 服务器,请谨慎使用。

swoole-hook-mysql

swoole-hook-mysql 不是一个扩展,而是 Swoole 的 Hook 特性。 如果你在编译时添加了 swoole,swoole-hook-mysql,你将启用 Swoole 的 mysqlndpdo_mysql 的协程模式。

swoole-hook-sqlite

swoole-hook-sqlite 不是一个扩展,而是 Swoole 的 Hook 特性。 如果你在编译时添加了 swoole,swoole-hook-sqlite,你将启用 Swoole 的 pdo_sqlite 的协程模式(Swoole 必须为 5.1 以上)。

swoole-hook-sqlite 与 pdo_sqlite 扩展冲突。如需使用 Swoole 和 pdo_sqlite,请删除 pdo_sqlite 扩展,启用 swooleswoole-hook-sqlite 即可。 该扩展包含了 pdo_sqlite 的协程环境的实现。

swow

  1. swow 仅支持 PHP >= 8.0 版本。

imap

  1. 该扩展目前不支持 Kerberos。
  2. 由于底层的 c-client、ext-imap 不是线程安全的。 无法在 --enable-zts 构建中使用它。
  3. 由于该扩展可能会从未来的 PHP 中删除,因此我们建议您寻找替代实现,例如 Webklex/php-imap

gd

  1. gd 扩展依赖了较多的额外图形库,默认情况下,直接使用 bin/spc build gd 不会引入和支持部分图形库,例如 libjpeglibavif 等, 需要使用 --with-libs 参数补全。目前支持 freetype,libjpeg,libavif,libwebp 四个库的支持,所以这里可以使用以下命令来让 gd 库引入它们:
bash
bin/spc build gd --with-libs=freetype,libjpeg,libavif,libwebp --build-cli

mcrypt

  1. 目前未支持,未来也不计划支持此扩展。#32

oci8

  1. oci8 是 Oracle 数据库的扩展,因为 Oracle 提供的扩展所依赖的库未提供静态编译版本(.a)或源代码,无法使用静态链接的方式将此扩展编译到 php 内,故无法支持。

xdebug

  1. Xdebug 是一个 Zend 扩展,Xdebug 的功能依赖于 PHP 的 Zend 引擎和底层代码,如果要将其静态编译到 PHP 中,可能需要巨量的 patch 代码,这是不可行的。
  2. macOS 平台可以通过在相同平台编译的 PHP 下编译一个 xdebug 扩展,并提取其中的 xdebug.so 文件,再在 static-php-cli 中使用 --no-strip 参数保留调试符号表,同时加入 ffi 扩展。 编译的 ./php 二进制可以通过指定 INI 配置并运行,例如./php -d 'zend_extension=xdebug.so' your-code.php

xml

  1. xml包括 xmlreader、xmlwriter、dom、simplexml 等,添加 xml 扩展时最好同时启用这些扩展。
  2. libxml 包含在 xml 扩展中。 启用 xml 相当于启用 libxml。

glfw

  1. glfw 扩展依赖 OpenGL,在 Linux 平台还依赖 X11 等环境,这些库都无法被轻易地动态链接。
  2. 在 macOS 系统下,我们可以动态链接系统的 OpenGL 和一些相关的库。

rar

  1. rar 扩展目前在 macOS x86_64 环境下与 common 扩展集合编译 phpmicro 存在问题。

pgsql

pgsql ssl 连接与 openssl 3.2.0 不兼容。相关链接:

pgsql 16.2 修复了这个 Bug,现在正常工作了。

在 pgsql 使用 SSL 连接时,可能存在 error:80000002:system library::No such file or directory 错误, 解决办法详见 FAQ - 无法使用 ssl

openssl

使用基于 openssl 的扩展(如 curl、pgsql 等网络库)时,可能存在 error:80000002:system library::No such file or directory 错误, 解决办法详见 FAQ - 无法使用 ssl

password-argon2

  1. password-argon2不是一个标准的扩展,它是 password_hash 函数的额外算法。
  2. 在Linux系统,password-argon2 的依赖库 libargon2libsodium 库冲突。

ffi

  1. 因为 Linux 系统的限制,虽然可以成功编译 ffi 扩展,但无法使用它加载其他 so 扩展。Linux 支持加载 so 扩展的前提是非静态编译,但动态编译和本项目的目的冲突。
  2. macOS 支持 ffi 扩展,但是部分内核下不包含调试符号时会出现错误。
  3. Windows 支持 ffi 扩展。

xhprof

xhprof 扩展包含三部分:xhprof_extensionxhprof_htmlxhprof_libs。编译的二进制中只包含 xhprof_extension。 如果需要使用 xhprof,请到 pecl.php.net/package/xhprof 下载源码,指定 xhprof_libsxhprof_html 路径来使用。

event

event 扩展在 macOS 系统下编译后暂无法使用 openpty 特性。相关 Issue:

parallel

parallel 扩展只支持 PHP 8.0 及以上版本,并只支持 ZTS 构建(--enable-zts)。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/guide/extensions.html b/zh/guide/extensions.html index b463e988..63a58bd7 100644 --- a/zh/guide/extensions.html +++ b/zh/guide/extensions.html @@ -18,7 +18,7 @@
Skip to content

扩展列表

  • yes: 已支持
  • 空白: 目前还不支持,或正在支持中
  • no with issue link: 确定不支持或无法支持
  • partial with issue link: 已支持,但是无法完美工作
Extension NameLinuxmacOSFreeBSDWindows
amqpyesyesyes
apcuyesyesyesyes
bcmathyesyesyesyes
bz2yesyesyesyes
calendaryesyesyesyes
ctypeyesyesyesyes
curlyesyesyesyes
dbayesyesyesyes
domyesyesyes
dsyesyesyesyes
enchant
eventyesyes
exifyesyesyesyes
ffinoyesyes
fileinfoyesyesyesyes
filteryesyesyesyes
ftpyesyesyesyes
gdyesyesyes
gettextyesyes
glfwnoyesno
gmpyesyes
iconvyesyesyes
igbinaryyesyes
imagickyesyes
imapyesyes
inotifyyesnono
intlyesyesno
ldapyesyes
libxmlyesyesyes
mbregexyesyesyesyes
mbstringyesyesyesyes
mcryptnononono
memcacheyesyes
memcachednoyes
mongodbyesyes
mysqliyesyesyesyes
mysqlndyesyesyesyes
oci8nonono
opcacheyesyesyesyes
opensslyesyesyesyes
parallelyesyesyes
password-argon2yesyes
pcntlyesyesyesno
pdoyesyesyesyes
pdo_mysqlyesyesyesyes
pdo_pgsqlyesyes
pdo_sqliteyesyesyes
pdo_sqlsrvyesyesyes
pgsqlyesyes
pharyesyesyesyes
posixyesyesyesno
protobufyesyes
raryespartialyes
readlineyesyes
redisyesyes
sessionyesyesyesyes
shmopyesyesyesyes
simdjsonyesyesyesyes
simplexmlyesyesyes
snappyyesyes
soapyesyesyes
socketsyesyesyesyes
sodiumyesyes
sqlite3yesyesyes
sqlsrvyesyesyes
ssh2yesyesyes
swooleyesyesno
swoole-hook-mysqlyesyesno
swoole-hook-pgsqlyespartialno
swoole-hook-sqliteyesyesno
swowyesyesyes
sysvmsgyesyesno
sysvsemyesyesno
sysvshmyesyesyes
tidyyesyes
tokenizeryesyesyesyes
uuidyesyes
uvyesyes
xdebugnonono
xhprofyesyes
xlswriteryesyes
xmlyesyesyes
xmlreaderyesyesyes
xmlwriteryesyesyes
xslyesyes
yacyesyesyes
yamlyesyesyes
zipyesyesyes
zlibyesyesyesyes
zstdyesyes

TIP

如果缺少您需要的扩展,您可以创建 功能请求

有些扩展或扩展依赖的库会有一些可选的特性,例如 gd 库可选支持 libwebp、freetype 等。 如果你只使用 bin/spc build gd --build-cli 是不会包含它们(static-php-cli 默认为最小依赖原则)。

你可以在编译时使用 --with-libs= 加入这些库,当本次编译的依赖库中包含它们,gd 会自动依赖它们启用这些特性。 (如:bin/spc build gd --with-libs=libwebp,freetype --build-cli

或者你也可以使用 --with-suggested-exts--with-suggested-libs 启用这些扩展和库所有可选的依赖。 (如:bin/spc build gd --with-suggested-libs --build-cli

如果你不知道某个扩展是否有可选特性,可以通过查看 spc 配置文件 或使用命令 bin/spc dev:extensions 查看(库依赖为 lib-suggests,扩展依赖为 ext-suggests)。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/guide/index.html b/zh/guide/index.html index e9e25d7a..43a84e5e 100644 --- a/zh/guide/index.html +++ b/zh/guide/index.html @@ -18,7 +18,7 @@
Skip to content

指南

static-php-cli 是一个用于构建静态编译的 PHP 二进制的工具,目前支持 Linux 和 macOS 系统。

在指南章节中,你将了解到如何使用 static-php-cli 构建独立的 php 程序。

编译环境

下面是架构支持情况,⚙️ 代表支持 GitHub Action 构建,💻 代表支持本地构建,空 代表暂不支持。

x86_64aarch64
macOS⚙️ 💻⚙️ 💻
Linux⚙️ 💻⚙️ 💻
Windows⚙️ 💻
FreeBSD💻💻

其中,Linux 目前仅在 Ubuntu、Debian、Alpine 发行版测试通过,其他发行版未进行测试,不能保证编译成功。 对于未经过测试的发行版,可以使用 Docker 等方式本地编译,避免环境导致的问题。

macOS 下支持 x86_64 和 Arm 两种架构,但在其中一个架构上编译的二进制无法直接在另一个架构上使用。 Rosetta 2 不能保证 Arm 架构编译的程序可以完全运行在 x86_64 环境下。

Windows 目前只支持 x86_64 架构,不支持 32 位 x86、不支持 arm64 架构。

PHP 支持版本

目前,static-php-cli 对 PHP 7.4 ~ 8.3 版本是支持的,对于 PHP 7.4 及更早版本理论上支持,只需下载时选择早期版本即可。 但由于部分扩展和特殊组件已对早期版本的 PHP 停止了支持,所以 static-php-cli 不会明确支持早期版本。 我们推荐你编译尽可能新的 PHP 版本,以获得更好的体验。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/guide/manual-build.html b/zh/guide/manual-build.html index 1d7ee92e..4b627cae 100644 --- a/zh/guide/manual-build.html +++ b/zh/guide/manual-build.html @@ -151,7 +151,7 @@ $ buildroot/bin/php -i | grep memory memory_limit => 8G => 8G

对于 static-php-cli 支持的对象、方法及接口,可以阅读源码,大部分的方法和对象都有相应的注释。

一般使用 -P 功能常用的对象及函数有:

TIP

static-php-cli 开放的方法非常多,文档中无法一一列举,但只要是 public function 并且不被标注为 @internal,均可调用。

- + \ No newline at end of file diff --git a/zh/guide/troubleshooting.html b/zh/guide/troubleshooting.html index 5aab1836..8c0c3ae3 100644 --- a/zh/guide/troubleshooting.html +++ b/zh/guide/troubleshooting.html @@ -18,7 +18,7 @@
Skip to content

故障排除

使用 static-php-cli 过程中可能会碰到各种各样的故障,这里将讲述如何自行查看错误并反馈 Issue。

下载失败问题

下载资源问题是 spc 最常见的问题之一。主要是由于 spc 下载资源使用的地址一般均为对应项目的官方网站或 GitHub 等,而这些网站可能偶尔会宕机、屏蔽 IP 地址。 目前 2.0.0 版本还没有加入自动重试机制,所以在遇到下载失败后,可以多次尝试调用下载命令。如果确认地址确实无法正常访问,可以提交 Issue 或 PR 更新地址。

doctor 无法修复

在绝大部分情况下,doctor 模块都可以对缺失的系统环境进行自动修复和安装,但也存在特殊的环境无法正常使用自动修复功能。

部分项目由于系统局限(如 Windows 下无法自动安装 Visual Studio 等软件),无法使用自动修复功能。 在遇到无法自动修复功能时,如果遇到 Some check items can not be fixed 字样,则表明无法自动修复,请根据终端显示的方法提交 Issue 或自行修复环境。

编译错误

遇到编译错误时,如果没有开启 --debug 日志,请先开启调试日志,然后确定报错的命令。 报错的终端输出对于修复编译错误非常重要,请在提交 Issue 时一并将终端日志的最后报错片段(或整个终端日志输出)上传,并且包含使用的 spc 命令和参数。

Released under the MIT License.

- + \ No newline at end of file diff --git a/zh/index.html b/zh/index.html index 0f447b6f..e4daaa32 100644 --- a/zh/index.html +++ b/zh/index.html @@ -18,7 +18,7 @@
Skip to content

static-php-cli

在 Linux、macOS、FreeBSD、Windows 上与 PHP 项目一起构建独立的 PHP 二进制文件,并包含流行的扩展。

Released under the MIT License.

- + \ No newline at end of file