fix(docker): raise PHP post_max_size for default 20MB upload chunks#798
fix(docker): raise PHP post_max_size for default 20MB upload chunks#798akirayamamoto wants to merge 2 commits intolibrespeed:masterfrom
Conversation
Review Summary by QodoFix PHP upload limits for 20MB default upload chunks
WalkthroughsDescription• Raise PHP post_max_size and upload_max_filesize to 32M • Fixes malformed responses from /backend/empty.php on uploads • Prevents PHP warnings and header modification failures • Adds docker/librespeed-php.ini with recommended PHP limits Diagramflowchart LR
A["20MB upload chunks"] -->|exceeds| B["PHP 8M post_max_size"]
B -->|triggers| C["Startup warning in response"]
C -->|causes| D["header() calls fail"]
D -->|results in| E["Malformed response"]
F["docker/librespeed-php.ini"] -->|sets 32M limits| G["Proper response handling"]
G -->|enables| H["Clean HTTP 200 response"]
File Changes1. Dockerfile
|
Code Review by Qodo
Context used 1. Hardcoded /usr/bin/php
|
7dd8342 to
362a1f1
Compare
speedtest_worker.js uploads in 20 MB chunks by default (xhr_ul_blob_megabytes: 20) but the official Docker images inherit PHP's stock post_max_size = 8M / upload_max_filesize = 2M, so every upload chunk: * triggers a "POST Content-Length ... exceeds the limit" warning (leaked into the response body of /backend/empty.php on the Debian variant where display_errors is on; suppressed but still emitted on Alpine where it's off); * causes empty.php's subsequent header() calls to fail with "Cannot modify header information - headers already sent", leaving the response without proper status, cache, or CORS directives. Ship a small docker/librespeed-php.ini with post_max_size = 32M, upload_max_filesize = 32M, memory_limit = 256M and COPY it into the right conf.d for each base image (/usr/local/etc/php/conf.d on Debian, /etc/php84/conf.d on Alpine). 99- prefix follows the NN-name.ini packaging convention so this loads after distro defaults but never silently shadows operator overrides. Verified post-fix on both variants: a 20 MB POST to /backend/empty.php returns HTTP 200 / 0 bytes with no warning leakage.
362a1f1 to
d088379
Compare
|
/review |
|
Persistent review updated to latest commit d088379 |
The previous build-time discovery via PHP_CONFIG_FILE_SCAN_DIR worked but invoked a PHP binary just to learn a path that's already a stable contract of each base image: * php:8-apache exports PHP_INI_DIR=/usr/local/etc/php as part of the docker-library image template, stable across PHP majors. Reference it directly in the COPY destination — no RUN, no validation needed. * Alpine's apk php-apache2 always installs mod_php's conf.d at /etc/phpXX/conf.d (currently /etc/php84). The FROM php:8-alpine image also ships its own PHP at /usr/local/etc/php/conf.d, but mod_php doesn't read from there. Glob /etc/php*/conf.d to track the apk-installed PHP major automatically; explicit error if the glob matches nothing. Net effect: Debian goes from a 5-line RUN block to a 1-line COPY. Alpine keeps a small RUN block but no longer invokes a PHP binary, so it doesn't matter which of the two PHP installs `php` resolves to via $PATH. Verified: both variants build, install the override at the right conf.d, mod_php reports post_max_size=32M, and a 20 MB POST to /backend/empty.php returns HTTP 200 / 0 bytes with no warnings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Important
Blocked by #800. That PR drops the unused docker-library PHP install from
Dockerfile.alpine. Once it lands, this PR will be rebased onto master and the comment about "two PHP installs" can be simplified or removed. Both PRs touch different parts ofDockerfile.alpineand don't conflict mechanically; the order is just to avoid carrying a stale comment.Fixes #797.
speedtest_worker.jsuploads in 20 MB chunks (xhr_ul_blob_megabytes: 20, speedtest_worker.js:59). Both Docker images inherit PHP's stockpost_max_size = 8M, so every chunk triggers a startup warning and breaksempty.php'sheader()calls. Full repro and effects in #797.Fix
New
docker/librespeed-php.ini:Copied into the right conf.d for each variant:
Dockerfile:${PHP_INI_DIR}/conf.d. The env var is set byphp:8-apacheto/usr/local/etc/phpand is stable across PHP majors.Dockerfile.alpine: globs/etc/php*/conf.dto find the apk-installed conf.d (currently/etc/php84). The FROMphp:8-alpineimage ships its own PHP at/usr/local/etc/php, but mod_php (loaded fromphp-apache2via apk) doesn't read from there. The glob tracks the apk PHP major and errors if nothing matches.Filename
99-librespeed.inifollows the NN-name.ini convention so it loads after packaged defaults but before any operator override at a higher prefix. 32M is the next round number above the worker's 20M default.Verified
Built both variants and tested via real Apache:
No warnings in body, Apache error log clean,
empty.php's response headers make it through.