123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- import{_ as s,c as i,o as e,a1 as a}from"./chunks/framework.gjrnbxUT.js";const u=JSON.parse('{"title":"Build (Linux, macOS, FreeBSD)","description":"","frontmatter":{},"headers":[],"relativePath":"en/guide/manual-build.md","filePath":"en/guide/manual-build.md"}'),n={name:"en/guide/manual-build.md"},t=a(`<h1 id="build-linux-macos-freebsd" tabindex="-1">Build (Linux, macOS, FreeBSD) <a class="header-anchor" href="#build-linux-macos-freebsd" aria-label="Permalink to "Build (Linux, macOS, FreeBSD)""></a></h1><p>This section covers the build process for Linux, macOS, and FreeBSD. If you want to build on Windows, also need to read <a href="./build-on-windows.html">Build on Windows</a>.</p><h3 id="build-locally-using-spc-binary-recommended" tabindex="-1">Build locally (using SPC binary) (recommended) <a class="header-anchor" href="#build-locally-using-spc-binary-recommended" aria-label="Permalink to "Build locally (using SPC binary) (recommended)""></a></h3><p>This project provides a binary file of static-php-cli. You can directly download the binary file of the corresponding platform and then use it to build static PHP. Currently, the platforms supported by <code>spc</code> binary are Linux and macOS.</p><p>Here's how to download from self-hosted server:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download from self-hosted nightly builds (sync with main branch)</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># For Linux x86_64</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -fsSL</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># For Linux aarch64</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -fsSL</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># macOS x86_64 (Intel)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -fsSL</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># macOS aarch64 (Apple)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -fsSL</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Windows (x86_64, win10 build 17063 or later)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl.exe</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -fsSL</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc.exe</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Add execute perm (Linux and macOS only)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">chmod</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +x</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ./spc</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Run (Linux and macOS)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./spc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Run (Windows powershell)</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">\\</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">spc.exe</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span></code></pre></div><blockquote><p>If you are using the packaged <code>spc</code> binary, you will need to replace the leading <code>bin/spc</code> with <code>./spc</code> in all the commands below.</p></blockquote><h3 id="build-locally-using-source-code" tabindex="-1">Build locally (using source code) <a class="header-anchor" href="#build-locally-using-source-code" aria-label="Permalink to "Build locally (using source code)""></a></h3><p>If you have problems using the spc binary, or if you need to modify the static-php-cli source code, download static-php-cli from the source code.</p><p>Currently, it supports building on macOS and Linux. macOS supports the latest version of the operating system and two architectures, while Linux supports Debian and derivative distributions, as well as Alpine Linux.</p><p>Because this project itself is developed using PHP, it is also necessary to install PHP on the system during compilation. This project also provides static binary PHP suitable for this project, which can be selected and used according to actual situations.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># clone repo</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/crazywhalecc/static-php-cli.git</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --depth=1</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> static-php-cli</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># You need to install the PHP environment first before running Composer and this project. The installation method can be referred to below.</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">composer</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span></span></code></pre></div><h3 id="use-system-php" tabindex="-1">Use System PHP <a class="header-anchor" href="#use-system-php" aria-label="Permalink to "Use System PHP""></a></h3><p>Below are some example commands for installing PHP and Composer in the system. It is recommended to search for the specific installation method yourself or ask the AI search engine to obtain the answer, which will not be elaborated here.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># [macOS], need install Homebrew first. See https://brew.sh/</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Remember change your composer executable path. For M1/M2 Chip mac, "/opt/homebrew/bin/", for Intel mac, "/usr/local/bin/". Or add it to your own path.</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">brew</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> wget</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wget</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://getcomposer.org/download/latest-stable/composer.phar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -O</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/your/bin/composer</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> && </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">chmod</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +x</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/your/bin/composer</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># [Debian], you need to make sure your php version >= 8.1 and composer >= 2.0</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php-cli</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> composer</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php-tokenizer</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># [Alpine]</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apk</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> add</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bash</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> file</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> wget</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> xz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81-common</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81-pcntl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81-tokenizer</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81-phar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81-posix</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php81-xml</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> composer</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>Currently, some versions of Ubuntu install older PHP versions, so no installation commands are provided. If necessary, it is recommended to add software sources such as ppa first, and then install the latest version of PHP and tokenizer, XML, and phar extensions.</p><p>Older versions of Debian may have an older (<= 7.4) version of PHP installed by default, it is recommended to upgrade Debian first.</p></div><h3 id="use-docker" tabindex="-1">Use Docker <a class="header-anchor" href="#use-docker" aria-label="Permalink to "Use Docker""></a></h3><p>If you don't want to install PHP and Composer runtime environment on your system, you can use the built-in Docker environment build script.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># To use directly, replace \`bin/spc\` with \`bin/spc-alpine-docker\` in all used commands</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc-alpine-docker</span></span></code></pre></div><p>The first time the command is executed, <code>docker build</code> will be used to build a Docker image. The default built Docker image is the <code>x86_64</code> architecture, and the image name is <code>cwcc-spc-x86_64</code>.</p><p>If you want to build <code>aarch64</code> static-php-cli in <code>x86_64</code> environment, you can use qemu to emulate the arm image to run Docker, but the speed will be very slow. Use command: <code>SPC_USE_ARCH=aarch64 bin/spc-alpine-docker</code>.</p><p>If it prompts that sudo is required to run after running, execute the following command once to grant static-php-cli permission to execute sudo:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SPC_USE_SUDO</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">yes</span></span></code></pre></div><h3 id="use-precompiled-static-php-binaries" tabindex="-1">Use Precompiled Static PHP Binaries <a class="header-anchor" href="#use-precompiled-static-php-binaries" aria-label="Permalink to "Use Precompiled Static PHP Binaries""></a></h3><p>If you don't want to use Docker and install PHP in the system, you can directly download the php binary cli program compiled by this project itself. The usage process is as follows:</p><p>Deploy the environment using the command, the command will download a static php-cli binary from <a href="https://dl.static-php.dev/static-php-cli/" target="_blank" rel="noreferrer">self-hosted server</a>. Next, it will automatically download Composer from <a href="https://getcomposer.org/download/latest-stable/composer.phar" target="_blank" rel="noreferrer">getcomposer</a> or <a href="https://mirrors.aliyun.com/composer/composer.phar" target="_blank" rel="noreferrer">Aliyun mirror</a>.</p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>Using precompiled static PHP binaries is currently only supported on Linux and macOS. The FreeBSD environment is currently not supported due to the lack of an automated build environment.</p></div><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/setup-runtime</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># For users with special network environments such as mainland China, you can use mirror sites (aliyun) to speed up the download speed</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/setup-runtime</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --mirror</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> china</span></span></code></pre></div><p>This script will download two files in total: <code>bin/php</code> and <code>bin/composer</code>. After the download is complete, there are two ways to use it:</p><ol><li>Add the <code>bin/</code> directory to the PATH: <code>export PATH="/path/to/your/static-php-cli/bin:$PATH"</code>, after adding the path, it is equivalent to installing PHP in the system, you can directly Use commands such as <code>composer</code>, <code>php -v</code>, or directly use <code>bin/spc</code>.</li><li>Direct call, such as executing static-php-cli command: <code>bin/php bin/spc --help</code>, executing Composer: <code>bin/php bin/composer update</code>.</li></ol><h2 id="command-download" tabindex="-1">Command - download <a class="header-anchor" href="#command-download" aria-label="Permalink to "Command - download""></a></h2><p>Use the command <code>bin/spc download</code> to download the source code required for compilation, including php-src and the source code of various dependent libraries.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download all dependencies</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --all</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download all dependent packages, and specify the main version of PHP to download, optional: 8.1, 8.2, 8.3, 8.4</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Also supports specific version of php release: 8.3.10, 8.2.22, etc.</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-php=8.3</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Show download progress bar while downloading (curl)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --debug</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Delete old download data</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --clean</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download specified dependencies</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php-src,micro,zstd,ext-zstd</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download only extensions and libraries to be compiled (use extensions, including suggested libraries)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=openssl,swoole,zip,pcntl,zstd</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download resources, prefer to download dependencies with pre-built packages (reduce the time to compile dependencies)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"curl,pcntl,xml,mbstring"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --prefer-pre-built</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download only the extensions and dependent libraries to be compiled (use extensions, excluding suggested libraries)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=openssl,swoole,zip,pcntl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --without-suggestions</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download only libraries to be compiled (use libraries, including suggested libraries and required libraries, can use --for-extensions together)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-libs=liblz4,libevent</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=pcntl,rar,xml</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download only libraries to be compiled (use libraries, excluding suggested libraries)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-libs=liblz4,libevent</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --without-suggestions</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># When downloading sources, ignore some source caches (always force download, e.g. switching PHP version)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=curl,pcntl,xml</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --ignore-cache-sources=php-src</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-php=8.3.10</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Set retry times (default is 0)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --retry=2</span></span></code></pre></div><p>If the network in your area is not good, or the speed of downloading the dependency package is too slow, you can download <code>download.zip</code> which is packaged regularly every week from GitHub Action, and use the command to directly use the zip archive as a dependency.</p><p>Dependent packages can be downloaded locally from <a href="https://github.com/static-php/static-php-cli-hosted/actions/workflows/download-cache.yml" target="_blank" rel="noreferrer">Action</a>. Enter Action and select the latest Workflow that has been successfully run, and download <code>download-files-x.y</code>.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --from-zip=/path/to/your/download.zip</span></span></code></pre></div><p>If a source cannot be downloaded all the time, or you need to download some specific version of the package, such as downloading the beta version of PHP, the old version of the library, etc., you can use the parameter <code>-U</code> or <code>--custom-url</code> to rewrite the download link, Make the downloader force the link you specify to download packages from this source. The method of use is <code>{source-name}:{url}</code>, which can rewrite the download URLs of multiple libraries at the same time. Also, it is available when downloading with the <code>--for-extensions</code> option.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Specifying to download a beta version of PHP8.3</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -U</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Specifying to download an older version of the curl library</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -U</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "curl:https://curl.se/download/curl-7.88.1.tar.gz"</span></span></code></pre></div><p>If the source you download is not a link, but a git repository, you can use <code>-G</code> or <code>--custom-git</code> to rewrite the download link, so that the downloader can force the use of the specified git repository to download packages from this source. The usage method is <code>{source-name}:{branch}:{url}</code>, which can rewrite the download link of multiple libraries at the same time. It is also available when downloading with the <code>--for-extensions</code> option.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Specifying to download the source code of the PHP extension from the specified branch of the git repository</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=redis</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -G</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "php-src:master:https://github.com/php/php-src.git"</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Download the latest code from the master branch of the swoole-src repository instead of PECL release version</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=swoole</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -G</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "swoole:master:https://github.com/swoole/swoole-src.git"</span></span></code></pre></div><h2 id="command-doctor" tabindex="-1">Command - doctor <a class="header-anchor" href="#command-doctor" aria-label="Permalink to "Command - doctor""></a></h2><p>If you can run <code>bin/spc</code> normally but cannot compile static PHP or dependent libraries normally, you can run <code>bin/spc doctor</code> first to check whether the system itself lacks dependencies.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Quick check</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> doctor</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Quickly check and fix when it can be automatically repaired (use package management to install dependent packages, only support the above-mentioned operating systems and distributions)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> doctor</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --auto-fix</span></span></code></pre></div><h2 id="command-build" tabindex="-1">Command - build <a class="header-anchor" href="#command-build" aria-label="Permalink to "Command - build""></a></h2><p>Use the build command to start building the static php binary. Before executing the <code>bin/spc build</code> command, be sure to use the <code>download</code> command to download sources. It is recommended to use <code>doctor</code> to check the environment.</p><h3 id="basic-build" tabindex="-1">Basic build <a class="header-anchor" href="#basic-build" aria-label="Permalink to "Basic build""></a></h3><p>You need to go to <a href="./extensions.html">Extension List</a> or <a href="./cli-generator.html">Command Generator</a> to select the extension you want to add, and then use the command <code>bin/spc build</code> to compile. You need to specify a compilation target, choose from the following parameters:</p><ul><li><code>--build-cli</code>: Build a cli sapi (command line interface, which can execute PHP code on the command line)</li><li><code>--build-fpm</code>: Build a fpm sapi (php-fpm, used in conjunction with other traditional fpm architecture software such as nginx)</li><li><code>--build-micro</code>: Build a micro sapi (used to build a standalone executable binary containing PHP code)</li><li><code>--build-embed</code>: Build an embed sapi (used to embed into other C language programs)</li><li><code>--build-all</code>: build all above sapi</li></ul><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Compile PHP with bcmath,curl,openssl,ftp,posix,pcntl extensions, the compilation target is cli</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,curl,openssl,ftp,posix,pcntl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Compile PHP with phar,curl,posix,pcntl,tokenizer extensions, compile target is micro</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> phar,curl,posix,pcntl,tokenizer</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-micro</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>If you need to repeatedly build and debug, you can delete the <code>buildroot/</code> and <code>source/</code> directories so that you can re-extract and build all you need from the downloaded source code package:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># remove</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">rm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -rf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> buildroot</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> source</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># build again</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,curl,openssl,ftp,posix,pcntl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span></code></pre></div></div><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>If you want to build multiple versions of PHP and don't want to build other dependent libraries repeatedly each time, you can use <code>switch-php-version</code> to quickly switch to another version and compile after compiling one version:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># switch to 8.4</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> switch-php-version</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8.4</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># build</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,curl,openssl,ftp,posix,pcntl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># switch to 8.1</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> switch-php-version</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 8.1</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># build</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,curl,openssl,ftp,posix,pcntl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span></code></pre></div></div><h3 id="debug" tabindex="-1">Debug <a class="header-anchor" href="#debug" aria-label="Permalink to "Debug""></a></h3><p>If you encounter problems during the compilation process, or want to view each executing shell command, you can use <code>--debug</code> to enable debug mode and view all terminal logs:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mysqlnd,pdo_mysql</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --debug</span></span></code></pre></div><h3 id="build-options" tabindex="-1">Build Options <a class="header-anchor" href="#build-options" aria-label="Permalink to "Build Options""></a></h3><p>During the compilation process, in some special cases, the compiler and the content of the compilation directory need to be intervened. You can try to use the following commands:</p><ul><li><code>--cc=XXX</code>: Specifies the execution command of the C language compiler (Linux default <code>musl-gcc</code> or <code>gcc</code>, macOS default <code>clang</code>)</li><li><code>--cxx=XXX</code>: Specifies the execution command of the C++ language compiler (Linux defaults to <code>g++</code>, macOS defaults to <code>clang++</code>)</li><li><code>--with-clean</code>: clean up old make files before compiling PHP</li><li><code>--enable-zts</code>: Make compiled PHP thread-safe version (default is NTS version)</li><li><code>--no-strip</code>: Do not run <code>strip</code> after compiling the PHP library to trim the binary file to reduce its size (the macOS binary file without trim can use dynamically linked third-party extensions)</li><li><code>--with-libs=XXX,YYY</code>: Compile the specified dependent library before compiling PHP, and activate some extended optional functions (such as libavif of the gd library, etc.)</li><li><code>--with-config-file-path=XXX</code>: Set the path in which to look for <code>php.ini</code> (Check <a href="./../faq/index.html#what-is-the-path-of-php-ini">here</a> for default paths)</li><li><code>--with-config-file-scan-dir=XXX</code>: Set the directory to scan for <code>.ini</code> files after reading <code>php.ini</code> (Check <a href="./../faq/index.html#what-is-the-path-of-php-ini">here</a> for default paths)</li><li><code>-I xxx=yyy</code>: Hard compile INI options into PHP before compiling (support multiple options, alias is <code>--with-hardcoded-ini</code>)</li><li><code>--with-micro-fake-cli</code>: When compiling micro, let micro's <code>PHP_SAPI</code> pretend to be <code>cli</code> (for compatibility with some programs that check <code>PHP_SAPI</code>)</li><li><code>--disable-opcache-jit</code>: Disable opcache jit (enabled by default)</li><li><code>-P xxx.php</code>: Inject external scripts during static-php-cli compilation (see <strong>Inject external scripts</strong> below for details)</li><li><code>--without-micro-ext-test</code>: After building micro.sfx, do not test the running results of different extensions in micro.sfx</li><li><code>--with-suggested-exts</code>: Add <code>ext-suggests</code> as dependencies when compiling</li><li><code>--with-suggested-libs</code>: Add <code>lib-suggests</code> as dependencies when compiling</li><li><code>--with-upx-pack</code>: Use UPX to reduce the size of the binary file after compilation (you need to use <code>bin/spc install-pkg upx</code> to install upx first)</li></ul><p>For hardcoding INI options, it works for cli, micro, embed sapi. Here is a simple example where we preset a larger <code>memory_limit</code> and disable the <code>system</code> function:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,pcntl,posix</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-all</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "memory_limit=4G"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "disable_functions=system"</span></span></code></pre></div><h2 id="command-micro-combine" tabindex="-1">Command - micro:combine <a class="header-anchor" href="#command-micro-combine" aria-label="Permalink to "Command - micro:combine""></a></h2><p>Use the <code>micro:combine</code> command to build the compiled <code>micro.sfx</code> and your code (<code>.php</code> or <code>.phar</code> file) into an executable binary. You can also use this command to directly build a micro binary injected with ini configuration.</p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>Injecting ini configuration refers to adding a special structure after micro.sfx to save ini configuration items before combining micro.sfx with PHP source code.</p><p>micro.sfx can identify the INI file header through a special byte, and the micro can be started with INI through the INI file header.</p><p>The original wiki of this feature is in <a href="https://github.com/easysoft/phpmicro/wiki/INI-settings" target="_blank" rel="noreferrer">phpmicro - Wiki</a>, and this feature may change in the future.</p></div><p>The following is the general usage, directly packaging the php source code into a file:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Before doing the packaging process, you should use \`build --build-micro\` to compile micro.sfx</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "<?php echo 'hello';"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Just use it</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./my-app</span></span></code></pre></div><p>You can use the following options to specify the file name to be output, and you can also specify micro.sfx in other paths for packaging.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># specify the output filename</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --output=custom-bin</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Use absolute path</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -O</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /tmp/my-custom-app</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Specify micro.sfx in other locations for packaging</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.app</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-micro=/path/to/your/micro.sfx</span></span></code></pre></div><p>If you want to inject ini configuration items, you can use the following parameters to add ini to the executable file from a file or command line option.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Specified using command-line options (-I is shorthand for --with-ini-set)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "a=b"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "foo=bar"</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Use ini file specification (-N is shorthand for --with-ini-file)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -N</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/your/custom.ini</span></span></code></pre></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Note, please do not directly use the PHP source code or the <code>php.ini</code> file in the system-installed PHP, it is best to manually write an ini configuration file that you need, for example:</p><div class="language-ini vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">; custom.ini</span></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">curl.cainfo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=/path/to/your/cafile.pem</span></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">memory_limit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=1G</span></span></code></pre></div><p>The ini injection of this command is achieved by appending a special structure after micro.sfx, which is different from the function of inserting hard-coded INI during compilation.</p></div><p>If you want to package phar, just replace <code>a.php</code> with the packaged phar file. But please note that micro.sfx under phar needs extra attention to the path problem, see <a href="./../develop/structure.html#phar-application-directory-issue">Developing - Phar directory issue</a>.</p><h2 id="command-extract" tabindex="-1">Command - extract <a class="header-anchor" href="#command-extract" aria-label="Permalink to "Command - extract""></a></h2><p>Use the command <code>bin/spc extract</code> to unpack and copy the source code required for compilation, including php-src and the source code of various dependent libraries (you need to specify the name of the library to be unpacked).</p><p>For example, after we have downloaded sources, we want to distribute and execute the build process, manually unpack and copy the package to a specified location, and we can use commands.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Unzip the downloaded compressed package of php-src and libxml2, and store the decompressed source code in the source directory</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> extract</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php-src,libxml2</span></span></code></pre></div><h2 id="dev-command-dev" tabindex="-1">Dev Command - dev <a class="header-anchor" href="#dev-command-dev" aria-label="Permalink to "Dev Command - dev""></a></h2><p>Debug commands refer to a collection of commands that can assist in outputting some information when you use static-php-cli to build PHP or modify and enhance the static-php-cli project itself.</p><ul><li><code>dev:extensions</code>: output all currently supported extension names, or output the specified extension information</li><li><code>dev:php-version</code>: output the currently compiled PHP version (by reading <code>php_version.h</code>)</li><li><code>dev:sort-config</code>: Sort the list of configuration files in the <code>config/</code> directory in alphabetical order</li><li><code>dev:lib-ver <lib-name></code>: Read the version from the source code of the dependency library (only available for specific dependency libraries)</li><li><code>dev:ext-ver <ext-name></code>: Read the corresponding version from the source code of the extension (only available for specific extensions)</li><li><code>dev:pack-lib <lib-name></code>: Package the specified library into a tar.gz file (maintainer only)</li><li><code>dev:gen-ext-docs</code>: Generate extension documentation (maintainer only)</li></ul><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># output all extensions information</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev:extensions</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Output the meta information of the specified extension</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev:extensions</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mongodb,curl,openssl</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Output the specified columns</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Available column name: lib-depends, lib-suggests, ext-depends, ext-suggests, unix-only, type</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev:extensions</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --columns=lib-depends,type,ext-depends</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Output the currently compiled PHP version</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># You need to decompress the downloaded PHP source code to the source directory first</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># You can use \`bin/spc extract php-src\` to decompress the source code separately</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev:php-version</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Sort the configuration files in the config/ directory in alphabetical order (e.g. ext.json)</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dev:sort-config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ext</span></span></code></pre></div><h2 id="command-install-pkg" tabindex="-1">Command - install-pkg <a class="header-anchor" href="#command-install-pkg" aria-label="Permalink to "Command - install-pkg""></a></h2><p>Use the command <code>bin/spc install-pkg</code> to download some precompiled or closed source tools and install them into the <code>pkgroot</code> directory.</p><p>When <code>bin/spc doctor</code> automatically repairs the Windows environment, tools such as nasm and perl will be downloaded, and the installation process of <code>install-pkg</code> will also be used.</p><p>Here is an example of installing the tool:</p><ul><li>Download and install UPX (Linux and Windows only): <code>bin/spc install-pkg upx</code></li></ul><h2 id="command-del-download" tabindex="-1">Command - del-download <a class="header-anchor" href="#command-del-download" aria-label="Permalink to "Command - del-download""></a></h2><p>In some cases, you need to delete single or multiple specified download source files and re-download them, such as switching PHP versions. The <code>bin/spc del-download</code> command is provided after the <code>2.1.0-beta.4</code> version. Specified source files can be deleted.</p><p>Deletes downloaded source files containing precompiled packages and source code named as keys in <code>source.json</code> or <code>pkg.json</code>. Here are some examples:</p><ul><li>Delete the old PHP source code and switch to download the 8.3 version: <code>bin/spc del-download php-src && bin/spc download php-src --with-php=8.3</code></li><li>Delete the download file of redis extension: <code>bin/spc del-download redis</code></li><li>Delete the downloaded musl-toolchain x86_64: <code>bin/spc del-download musl-toolchain-x86_64-linux</code></li></ul><h2 id="inject-external-script" tabindex="-1">Inject External Script <a class="header-anchor" href="#inject-external-script" aria-label="Permalink to "Inject External Script""></a></h2><p>Injecting external scripts refers to inserting one or more scripts during the static-php-cli compilation process to more flexibly support parameter modifications and source code patches in different environments.</p><p>Under normal circumstances, this function mainly solves the problem that the patch cannot be modified by modifying the static-php-cli code when compiling with <code>spc</code> binary.</p><p>There is another situation: your project directly depends on the <code>crazywhalecc/static-php-cli</code> repository and is synchronized with main branch, but some proprietary modifications are required, and these feature are not suitable for merging into the main branch.</p><p>In view of the above situation, in the official version 2.0.0, static-php-cli has added multiple event trigger points. You can write an external <code>xx.php</code> script and pass it in through the command line parameter <code>-P</code> and execute.</p><p>When writing to inject external scripts, the methods you will use are <code>builder()</code> and <code>patch_point()</code>. Among them, <code>patch_point()</code> obtains the name of the current event, and <code>builder()</code> obtains the BuilderBase object.</p><p>Because the incoming patch point does not distinguish between events, you must write the code you want to execute in <code>if(patch_point() === 'your_event_name')</code>, otherwise it will be executed repeatedly in other events.</p><p>The following are the supported <code>patch_point</code> event names and corresponding locations:</p><table tabindex="0"><thead><tr><th>Event name</th><th>Event description</th></tr></thead><tbody><tr><td>before-libs-extract</td><td>Triggered before the dependent libraries extracted</td></tr><tr><td>after-libs-extract</td><td>Triggered after the compiled dependent libraries extracted</td></tr><tr><td>before-php-extract</td><td>Triggered before PHP source code extracted</td></tr><tr><td>after-php-extract</td><td>Triggered after PHP source code extracted</td></tr><tr><td>before-micro-extract</td><td>Triggered before phpmicro extract</td></tr><tr><td>after-micro-extract</td><td>Triggered after phpmicro extracted</td></tr><tr><td>before-exts-extract</td><td>Triggered before the extension (to be compiled) extracted to the PHP source directory</td></tr><tr><td>after-exts-extract</td><td>Triggered after the extension extracted to the PHP source directory</td></tr><tr><td>before-library[<em>name</em>]-build</td><td>Triggered before the library named <code>name</code> is compiled (such as <code>before-library[postgresql]-build</code>)</td></tr><tr><td>after-library[<em>name</em>]-build</td><td>Triggered after the library named <code>name</code> is compiled</td></tr><tr><td>before-php-buildconf</td><td>Triggered before compiling PHP command <code>./buildconf</code></td></tr><tr><td>before-php-configure</td><td>Triggered before compiling PHP command <code>./configure</code></td></tr><tr><td>before-php-make</td><td>Triggered before compiling PHP command <code>make</code></td></tr><tr><td>before-sanity-check</td><td>Triggered after compiling PHP but before running extended checks</td></tr></tbody></table><p>The following is a simple example of temporarily modifying the PHP source code. Enable the CLI function to search for the <code>php.ini</code> configuration in the current working directory:</p><div class="language-php vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">php</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// a.php</span></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"><?</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">php</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// patch it before \`./buildconf\` executed</span></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">patch_point</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">===</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'before-php-buildconf'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\SPC\\store\\FileSystem</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">::</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">replaceFileStr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> SOURCE_PATH</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> .</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '/php-src/sapi/cli/php_cli.c'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
- <span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'sapi_module->php_ini_ignore_cwd = 1;'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
- <span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'sapi_module->php_ini_ignore_cwd = 0;'</span></span>
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> );</span></span>
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mbstring</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -P</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> a.php</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Write in ./</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'memory_limit=8G'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ./php.ini</span></span></code></pre></div><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>$ buildroot/bin/php -i | grep Loaded</span></span>
- <span class="line"><span>Loaded Configuration File => /Users/jerry/project/git-project/static-php-cli/php.ini</span></span>
- <span class="line"><span></span></span>
- <span class="line"><span>$ buildroot/bin/php -i | grep memory</span></span>
- <span class="line"><span>memory_limit => 8G => 8G</span></span></code></pre></div><p>For the objects, methods and interfaces supported by static-php-cli, you can read the source code. Most methods and objects have corresponding comments.</p><p>Commonly used objects and functions using the <code>-P</code> function are:</p><ul><li><code>SPC\\store\\FileSystem</code>: file management class <ul><li><code>::replaceFileStr(string $filename, string $search, $replace)</code>: Replace file string content</li><li><code>::replaceFileStr(string $filename, string $pattern, $replace)</code>: Regularly replace file content</li><li><code>::replaceFileUser(string $filename, $callback)</code>: User-defined function replaces file content</li><li><code>::copyDir(string $from, string $to)</code>: Recursively copy a directory to another location</li><li><code>::convertPath(string $path)</code>: Convert the path delimiter to the current system delimiter</li><li><code>::scanDirFiles(string $dir, bool $recursive = true, bool|string $relative = false, bool $include_dir = false)</code>: Traverse directory files</li></ul></li><li><code>SPC\\builder\\BuilderBase</code>: Build object <ul><li><code>->getPatchPoint()</code>: Get the current injection point name</li><li><code>->getOption(string $key, $default = null)</code>: Get command line and compile-time options</li><li><code>->getPHPVersionID()</code>: Get the currently compiled PHP version ID</li><li><code>->getPHPVersion()</code>: Get the currently compiled PHP version number</li><li><code>->setOption(string $key, $value)</code>: Set options</li><li><code>->setOptionIfNotExists(string $key, $value)</code>: Set option if option does not exist</li></ul></li></ul><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>static-php-cli has many open methods, which cannot be listed in the docs, but as long as it is a <code>public function</code> and is not marked as <code>@internal</code>, it theoretically can be called.</p></div><h2 id="multiple-builds" tabindex="-1">Multiple builds <a class="header-anchor" href="#multiple-builds" aria-label="Permalink to "Multiple builds""></a></h2><p>If you need to build multiple times locally, the following method can save you time downloading resources and compiling.</p><ul><li>If you only switch the PHP version without changing the dependent libraries, you can use <code>bin/spc switch-php-version</code> to quickly switch the PHP version, and then re-run the same <code>build</code> command.</li><li>If you want to rebuild once, but do not re-download the source code, you can first <code>rm -rf buildroot source</code> to delete the compilation directory and source code directory, and then rebuild.</li><li>If you want to update a version of a dependency, you can use <code>bin/spc del-download <source-name></code> to delete the specified source code, and then use <code>download <source-name></code> to download it again.</li><li>If you want to update all dependent versions, you can use <code>bin/spc download --clean</code> to delete all downloaded sources, and then download them again.</li></ul><h2 id="embed-usage" tabindex="-1">embed usage <a class="header-anchor" href="#embed-usage" aria-label="Permalink to "embed usage""></a></h2><p>If you want to embed static-php into other C language programs, you can use <code>--build-embed</code> to build an embed version of PHP.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> {your</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> extensions}</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-embed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --debug</span></span></code></pre></div><p>Under normal circumstances, PHP embed will generate <code>php-config</code> after compilation. For static-php, we provide <code>spc-config</code> to obtain the parameters during compilation. In addition, when using embed SAPI (libphp.a), you need to use the same compiler as libphp, otherwise there will be a link error.</p><p>Here is the basic usage of spc-config:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># output all flags and options</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc-config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> curl,zlib,phar,openssl</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># output libs</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc-config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> curl,zlib,phar,openssl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --libs</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># output includes</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc-config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> curl,zlib,phar,openssl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --includes</span></span></code></pre></div><p>By default, static-php uses the following compilers on different systems:</p><ul><li>macOS: <code>clang</code></li><li>Linux (Alpine Linux): <code>gcc</code></li><li>Linux (glibc based distros, x86_64): <code>/usr/local/musl/bin/x86_64-linux-musl-gcc</code></li><li>Linux (glibc based distros, aarch64): <code>/usr/local/musl/bin/aarch64-linux-musl-gcc</code></li><li>FreeBSD: <code>clang</code></li></ul><p>Here is an example of using embed SAPI:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// embed.c</span></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> <sapi/embed/php_embed.h></span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;"> argc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> **</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">argv</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">){</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> PHP_EMBED_START_BLOCK</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(argc,argv)</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> zend_file_handle file_handle;</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> zend_stream_init_filename</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">file_handle,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"embed.php"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">php_execute_script</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">file_handle) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> FAILURE){</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> php_printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"Failed to execute PHP script.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> PHP_EMBED_END_BLOCK</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><div class="language-php vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">php</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"><?</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">php</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// embed.php</span></span>
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> "Hello world!</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\n</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span></code></pre></div><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># compile in debian/ubuntu x86_64</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">/usr/local/musl/bin/x86_64-linux-musl-gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> embed.c</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc-config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,zlib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">-static</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> embed</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># compile in macOS/FreeBSD</span></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">clang</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> embed.c</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc-config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bcmath,zlib</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">-o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> embed</span></span>
- <span class="line"></span>
- <span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./embed</span></span>
- <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># out: Hello world!</span></span></code></pre></div>`,119),l=[t];function p(o,h,d,c,r,k){return e(),i("div",null,l)}const F=s(n,[["render",p]]);export{u as __pageData,F as default};
|