You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/performance.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,19 +34,18 @@ you need to create a worker script and to be sure that the app is not leaking me
34
34
35
35
## Don't Use musl
36
36
37
-
The static binaries we provide and the Alpine Linux variant of the official Docker images
38
-
are using [the musl libc](https://musl.libc.org).
37
+
The Alpine Linux variant of the official Docker images and the default binaries we provide are using [the musl libc](https://musl.libc.org).
39
38
40
-
PHP is known to be [significantly slower](https://gitlab.alpinelinux.org/alpine/aports/-/issues/14381) when using this alternative C library instead of the traditional GNU library,
41
-
especially when compiled in ZTS mode (thread-safe), which is required for FrankenPHP.
39
+
PHP is known to be [slower](https://gitlab.alpinelinux.org/alpine/aports/-/issues/14381) when using this alternative C library instead of the traditional GNU library,
40
+
especially when compiled in ZTS mode (thread-safe), which is required for FrankenPHP. The difference can be significant in a heavily threaded environment.
42
41
43
42
Also, [some bugs only happen when using musl](https://github.com/php/php-src/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen+label%3ABug+musl).
44
43
45
-
In production environments, we strongly recommend to use the glibc.
44
+
In production environments, we recommend using FrankenPHP linked against glibc.
46
45
47
-
This can be achieved by using the Debian Docker images (the default) and [by compiling FrankenPHP from sources](compile.md).
46
+
This can be achieved by using the Debian Docker images (the default), downloading the -gnu suffix binary from our [Releases](https://github.com/dunglas/frankenphp/releases), or by [compiling FrankenPHP from sources](compile.md).
48
47
49
-
Alternatively, we provide static binaries compiled with [the mimalloc allocator](https://github.com/microsoft/mimalloc), which makes FrankenPHP+musl faster (but still slower than FrankenPHP+glibc).
48
+
Alternatively, we provide static musl binaries compiled with [the mimalloc allocator](https://github.com/microsoft/mimalloc), which alleviates the problems in threaded scenarios.
Instead of using a local installation of the PHP library,
4
-
it's possible to create a static build of FrankenPHP thanks to the great [static-php-cli project](https://github.com/crazywhalecc/static-php-cli) (despite its name, this project support all SAPIs, not only CLI).
4
+
it's possible to create a static or mostly static build of FrankenPHP thanks to the great [static-php-cli project](https://github.com/crazywhalecc/static-php-cli) (despite its name, this project supports all SAPIs, not only CLI).
5
5
6
-
With this method, a single, portable, binary will contain the PHP interpreter, the Caddy web server and FrankenPHP!
6
+
With this method, a single, portable, binary will contain the PHP interpreter, the Caddy web server, and FrankenPHP!
7
+
8
+
Fully static native executables require no dependencies at all and can even be run on [`scratch` Docker image](https://docs.docker.com/build/building/base-images/#create-a-minimal-base-image-using-scratch).
9
+
However, they can't load dynamic PHP extensions (such as Xdebug) and have some limitations because they are using the musl libc.
10
+
11
+
Mostly static binaries only require `glibc` and can load dynamic extensions.
12
+
13
+
When possible, we recommend using glibc-based, mostly static builds.
7
14
8
15
FrankenPHP also supports [embedding the PHP app in the static binary](embed.md).
9
16
10
17
## Linux
11
18
12
-
We provide a Docker image to build a Linux static binary:
19
+
We provide Docker images to build static Linux binaries:
20
+
21
+
### musl-Based, Fully Static Build
22
+
23
+
For a fully-static binary that runs on any Linux distribution without dependencies but doesn't support dynamic loading of extensions:
This binary supports all glibc versions 2.17 and superior but does not run on musl-based systems (like Alpine Linux).
46
+
47
+
The resulting mostly static (except `glibc`) binary is named `frankenphp` and is available in the current directory.
48
+
49
+
If you want to build the static binary without Docker, take a look at the macOS instructions, which also work for Linux.
22
50
23
51
### Custom Extensions
24
52
25
-
By default, most popular PHP extensions are compiled.
53
+
By default, the most popular PHP extensions are compiled.
26
54
27
55
To reduce the size of the binary and to reduce the attack surface, you can choose the list of extensions to build using the `PHP_EXTENSIONS` Docker ARG.
28
56
29
57
For instance, run the following command to only build the `opcache` extension:
In this example, we add the [Souin](https://souin.io) HTTP cache module for Caddy as well as the [cbrotli](https://github.com/dunglas/caddy-cbrotli), [Mercure](https://mercure.rocks) and [Vulcain](https://vulcain.rocks) modules.
58
86
59
87
> [!TIP]
60
88
>
61
-
> The cbrotli, Mercure and Vulcain modules are included by default if `XCADDY_ARGS` is empty or not set.
89
+
> The cbrotli, Mercure, and Vulcain modules are included by default if `XCADDY_ARGS` is empty or not set.
62
90
> If you customize the value of `XCADDY_ARGS`, you must include them explicitly if you want them to be included.
63
91
64
92
See also how to [customize the build](#customizing-the-build)
@@ -68,7 +96,7 @@ See also how to [customize the build](#customizing-the-build)
68
96
If you hit the GitHub API rate limit, set a GitHub Personal Access Token in an environment variable named `GITHUB_TOKEN`:
Note: this script also works on Linux (and probably on other Unixes), and is used internally by the Docker based static builder we provide.
113
+
Note: this script also works on Linux (and probably on other Unixes), and is used internally by the Docker images we provide.
86
114
87
115
## Customizing The Build
88
116
@@ -97,6 +125,37 @@ script to customize the static build:
97
125
*`EMBED`: path of the PHP application to embed in the binary
98
126
*`CLEAN`: when set, libphp and all its dependencies are built from scratch (no cache)
99
127
*`NO_COMPRESS`: don't compress the resulting binary using UPX
100
-
*`DEBUG_SYMBOLS`: when set, debug-symbols will not be stripped and will be added within the binary
101
-
*`MIMALLOC`: (experimental, Linux-only) replace musl's mallocng by [mimalloc](https://github.com/microsoft/mimalloc) for improved performance
128
+
*`DEBUG_SYMBOLS`: when set, debug-symbols will not be stripped and will be added to the binary
129
+
*`MIMALLOC`: (experimental, Linux-only) replace musl's mallocng by [mimalloc](https://github.com/microsoft/mimalloc) for improved performance. We only recommend using this for musl targeting builds, for glibc prefer disabling this option and using [`LD_PRELOAD`](https://microsoft.github.io/mimalloc/overrides.html) when you run your binary instead.
102
130
*`RELEASE`: (maintainers only) when set, the resulting binary will be uploaded on GitHub
131
+
132
+
## Extensions
133
+
134
+
With the glibc or macOS-based binaries, you can load PHP extensions dynamically. However, these extensions will have to be compiled with ZTS support.
135
+
Since most package managers do not currently offer ZTS versions of their extensions, you will have to compile them yourself.
136
+
137
+
For this, you can build and run the `static-builder-gnu` Docker container, remote into it, and compile the extensions with `./configure --with-php-config=/go/src/app/dist/static-php-cli/buildroot/bin/php-config`.
138
+
139
+
Example steps for [the Xdebug extension](https://xdebug.org):
This will have created `frankenphp` and `xdebug-zts.so` in the current directory.
161
+
If you move the `xdebug-zts.so` into your extension directory, add `zend_extension=xdebug-zts.so` to your php.ini and run FrankenPHP, it will load Xdebug.
0 commit comments