Skip to content

Commit b730d7f

Browse files
committed
Refactor PHP configuration and Docker setup:
- Mount `php.ini` in `docker-compose.yml` for better flexibility. - Remove redundant `php.ini` copies and preload directives in Dockerfiles. - Consolidate `tokio_sapi` extension enablement using `tokio_sapi.ini`.
1 parent 6b6f23a commit b730d7f

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,8 @@ RUN EXT_DIR=$(php-config --extension-dir) && \
8787
COPY --from=builder /app/ext/modules/tokio_sapi.so /tmp/tokio_sapi.so
8888
RUN EXT_DIR=$(php-config --extension-dir) && \
8989
cp /tmp/tokio_sapi.so "$EXT_DIR/" && \
90-
rm /tmp/tokio_sapi.so /tmp/php_ext_dir
91-
92-
# Copy PHP configuration (OPcache, JIT, tokio_sapi)
93-
COPY php.ini /usr/local/etc/php/conf.d/tokio_php.ini
94-
95-
# Enable preloading for dev image
96-
RUN echo "opcache.preload=/var/www/html/preload.php" >> /usr/local/etc/php/conf.d/tokio_php.ini && \
97-
echo "opcache.preload_user=www-data" >> /usr/local/etc/php/conf.d/tokio_php.ini
90+
rm /tmp/tokio_sapi.so /tmp/php_ext_dir && \
91+
echo "extension=tokio_sapi.so" >> /usr/local/etc/php/conf.d/tokio_sapi.ini
9892

9993
# Create app directory
10094
WORKDIR /app

Dockerfile.release

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ COPY build.rs ./
8383
RUN RUSTFLAGS="-C target-feature=-crt-static" cargo build --release
8484

8585
# =============================================================================
86-
# Distribution stage - extract binaries and config
86+
# Distribution stage - extract binaries only
8787
# =============================================================================
8888
FROM scratch AS dist
8989

@@ -93,9 +93,6 @@ COPY --from=builder /app/target/release/tokio_php /tokio_php
9393
# PHP extension
9494
COPY --from=builder /app/ext/modules/tokio_sapi.so /tokio_sapi.so
9595

96-
# PHP configuration
97-
COPY php.ini /php.ini
98-
9996
# =============================================================================
10097
# Minimal runtime stage (default)
10198
# =============================================================================
@@ -110,10 +107,8 @@ RUN apk add --no-cache libgcc
110107
COPY --from=builder /app/ext/modules/tokio_sapi.so /tmp/tokio_sapi.so
111108
RUN EXT_DIR=$(php-config --extension-dir) && \
112109
cp /tmp/tokio_sapi.so "$EXT_DIR/" && \
113-
rm /tmp/tokio_sapi.so
114-
115-
# Copy PHP configuration (OPcache, JIT, tokio_sapi)
116-
COPY php.ini /usr/local/etc/php/conf.d/tokio_php.ini
110+
rm /tmp/tokio_sapi.so && \
111+
echo "extension=tokio_sapi.so" >> /usr/local/etc/php/conf.d/tokio_sapi.ini
117112

118113
# Copy binary
119114
COPY --from=builder /app/target/release/tokio_php /usr/local/bin/tokio_php

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ services:
4242
- REQUEST_TIMEOUT=${REQUEST_TIMEOUT:-2m}
4343
volumes:
4444
- ./www:/var/www/html:ro
45+
# PHP configuration (OPcache, JIT, etc.)
46+
- ./php.ini:/usr/local/etc/php/conf.d/tokio_php.ini:ro
4547
restart: unless-stopped
4648
healthcheck:
4749
test: ["CMD", "curl", "-sf", "http://localhost:9090/health"]
@@ -82,6 +84,7 @@ services:
8284
- REQUEST_TIMEOUT=${REQUEST_TIMEOUT:-2m}
8385
volumes:
8486
- ./www:/var/www/html:ro
87+
- ./php.ini:/usr/local/etc/php/conf.d/tokio_php.ini:ro
8588
- ./certs:/certs:ro
8689
restart: unless-stopped
8790
healthcheck:

php.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
; tokio_php configuration
2+
;
3+
; Mount this file via docker-compose:
4+
; volumes:
5+
; - ./php.ini:/usr/local/etc/php/conf.d/tokio_php.ini:ro
26

37
[opcache]
48
opcache.enable = 1
@@ -10,13 +14,11 @@ opcache.validate_timestamps = 0
1014
opcache.revalidate_freq = 0
1115
opcache.jit_buffer_size = 64M
1216
opcache.jit = tracing
13-
; Preloading - runs preload.php at startup to cache framework classes
17+
18+
; Preloading - uncomment for frameworks (Laravel, Symfony)
1419
; opcache.preload = /var/www/html/preload.php
1520
; opcache.preload_user = www-data
1621

17-
[tokio_sapi]
18-
extension = tokio_sapi.so
19-
2022
[Session]
2123
session.save_path = /tmp
2224
session.use_cookies = 1

0 commit comments

Comments
 (0)