Skip to content

Commit 83f0271

Browse files
committed
Enhance FrankenPHP configuration for performance and caching
- Updated Dockerfile to include additional PHP environment variables for OPcache and FrankenPHP threading configurations. - Modified Caddyfile to improve encoding settings with minimum length and content type matching, and added precompression for static file serving. - Adjusted worker configuration files to utilize new threading parameters for better resource management.
1 parent 7f7369d commit 83f0271

5 files changed

Lines changed: 49 additions & 13 deletions

File tree

src/common/usr/local/etc/php/conf.d/docker-php.ini renamed to src/common/usr/local/etc/php/conf.d/serversideup-docker-php.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ disable_classes =
348348
; the file operations performed.
349349
; Note: if open_basedir is set, the cache is disabled
350350
; https://php.net/realpath-cache-size
351-
;realpath_cache_size = 4096k
351+
realpath_cache_size = ${PHP_REALPATH_CACHE_SIZE}
352352

353353
; Duration of time, in seconds for which to cache realpath information for a given
354354
; file or directory. For systems with rarely changing files, consider increasing this
@@ -372,7 +372,7 @@ zend.multibyte = ${PHP_ZEND_MULTIBYTE}
372372

373373
; Check for BOM (Byte Order Mark) and see if the file contains valid
374374
; multibyte characters. This detection is performed before processing
375-
; of __halt_compiler(). Available only in Zend Multibyte mode.
375+
; of __halt_compiler(). Available only in Zend Multibyte mode.
376376
zend.detect_unicode = ${PHP_ZEND_DETECT_UNICODE}
377377

378378
; Allows to include or exclude arguments from stack traces generated for exceptions.
@@ -1832,7 +1832,7 @@ opcache.save_comments=${PHP_OPCACHE_SAVE_COMMENTS}
18321832
; Configure the JIT compiler.
18331833
opcache.jit=${PHP_OPCACHE_JIT}
18341834

1835-
; The amount of shared memory to reserve for compiled JIT code. A zero value disables the JIT.
1835+
; The amount of shared memory to reserve for compiled JIT code. A zero value disables the JIT.
18361836
opcache.jit_buffer_size=${PHP_OPCACHE_JIT_BUFFER_SIZE}
18371837

18381838
; If enabled, compilation warnings (including notices and deprecations) will
@@ -1937,12 +1937,12 @@ opcache.enable_file_override=${PHP_OPCACHE_ENABLE_FILE_OVERRIDE}
19371937
; Specifies a PHP script that is going to be compiled and executed at server
19381938
; start-up.
19391939
; https://php.net/opcache.preload
1940-
;opcache.preload=
1940+
opcache.preload=${PHP_OPCACHE_PRELOAD}
19411941

19421942
; Preloading code as root is not allowed for security reasons. This directive
19431943
; facilitates to let the preloading to be run as another user.
19441944
; https://php.net/opcache.preload_user
1945-
;opcache.preload_user=
1945+
opcache.preload_user=${PHP_OPCACHE_PRELOAD_USER}
19461946

19471947
; Prevents caching files that are less than this number of seconds old. It
19481948
; protects from caching of incompletely updated files. In case all file updates

src/variations/frankenphp/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ FROM common AS final
4040
ARG REPOSITORY_BUILD_VERSION='dev'
4141

4242
ENV \
43-
PHP_VARIABLES_ORDER="GPCS"
43+
PHP_VARIABLES_ORDER="GPCS" \
44+
PHP_OPCACHE_PRELOAD="" \
45+
PHP_OPCACHE_PRELOAD_USER="www-data" \
46+
PHP_OPCACHE_MAX_ACCELERATED_FILES="32531" \
47+
PHP_OPCACHE_MEMORY_CONSUMPTION="256" \
48+
PHP_REALPATH_CACHE_SIZE="4096K" \
49+
PHP_REALPATH_CACHE_TTL="600" \
50+
PHP_OPCACHE_JIT="off" \
51+
PHP_OPCACHE_JIT_BUFFER_SIZE="64M" \
52+
FRANKENPHP_THREADS=8 \
53+
FRANKENPHP_MAX_THREADS=32 \
54+
FRANKENPHP_WORKER_THREADS=4
4455

4556
LABEL org.opencontainers.image.title="yieldstudio/php (frankenphp)" \
4657
org.opencontainers.image.description="Supercharge your PHP experience. Based off the official PHP images and serversideup/php, yieldstudio/php includes pre-configured PHP extensions and settings for enhanced performance and security. Optimized for Laravel and WordPress." \

src/variations/frankenphp/etc/frankenphp/Caddyfile

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,18 @@ fd00::/8 \
7272
(php-app-common) {
7373
root * {$CADDY_APP_PUBLIC_PATH:/var/www/html/public}
7474

75-
encode zstd br gzip
75+
encode {
76+
zstd
77+
br
78+
gzip
79+
minimum_length 512
80+
match {
81+
header Content-Type text/*
82+
header Content-Type application/json*
83+
header Content-Type application/javascript*
84+
header Content-Type application/xml*
85+
}
86+
}
7687

7788
# Match php log levels to Caddy address log levels
7889
import log-level/address/{$LOG_OUTPUT_LEVEL:info}.caddyfile
@@ -93,10 +104,13 @@ fd00::/8 \
93104
php_server {
94105
{$CADDY_PHP_SERVER_OPTIONS}
95106
}
96-
file_server
107+
108+
file_server {
109+
precompressed br gzip
110+
}
97111

98112
import performance
99-
import security
113+
import security
100114

101115
{$CADDY_SERVER_EXTRA_DIRECTIVES}
102116
}
@@ -106,6 +120,13 @@ fd00::/8 \
106120
@meta path /favicon.ico /robots.txt
107121
log_skip @meta
108122

123+
# Build assets: ultra-long cache + precompressed
124+
@build {
125+
path /build/*
126+
}
127+
header @build Cache-Control "public, immutable, max-age=31536000"
128+
header @build X-Content-Type-Options "nosniff"
129+
109130
# Static assets (long cache)
110131
@static {
111132
path *.css *.css.map *.js *.js.map *.jpg *.jpeg *.png *.gif *.ico *.cur *.heic *.webp *.tif *.tiff *.mp3 *.m4a *.aac *.ogg *.midi *.mid *.wav *.mp4 *.mov *.webm *.mpeg *.mpg *.avi *.ogv *.flv *.wmv *.htc *.gz *.svg *.svgz *.woff2 *.woff
@@ -127,7 +148,7 @@ fd00::/8 \
127148

128149
(security) {
129150
# Reject dot files and certain file extensions
130-
@rejected path *.bak *.conf *.dist *.fla *.ini *.inc *.inci *.log *.orig *.psd *.sh *.sql *.swo *.swp *.swop */.*
151+
@rejected path *.bak *.conf *.dist *.fla *.ini *.inc *.inci *.log *.orig *.psd *.sh *.sql *.swo *.swp *.swop
131152

132153
# Return 403 Forbidden for rejected files
133154
respond @rejected 403
@@ -163,4 +184,4 @@ fd00::/8 \
163184
import ssl-mode/{$SSL_MODE:off}.caddyfile
164185

165186
# Add additional Caddy configuration files from the caddyfile.d directory
166-
import caddyfile.d/*.caddyfile
187+
import caddyfile.d/*.caddyfile

src/variations/frankenphp/etc/frankenphp/worker/frankenphp.caddyfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# FrankenPHP worker configuration
21
frankenphp {
32
php_ini variables_order "EGPCS"
3+
num_threads {$FRANKENPHP_THREADS:8}
4+
max_threads {$FRANKENPHP_MAX_THREADS:32}
45
worker {
56
file "{$CADDY_APP_PUBLIC_PATH:/var/www/html/public}/frankenphp-worker.php"
7+
num {$FRANKENPHP_WORKER_THREADS:4}
68
{$FRANKENPHP_WORKER_CONFIG}
79
}
810
{$FRANKENPHP_CONFIG}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
frankenphp {
2+
num_threads {$FRANKENPHP_THREADS:8}
3+
max_threads {$FRANKENPHP_MAX_THREADS:32}
24
{$FRANKENPHP_CONFIG}
3-
}
5+
}

0 commit comments

Comments
 (0)