FrankenPHP高负载下崩溃问题求助:需自动重启及兼容性排查
高负载下FrankenPHP崩溃退出问题及排查记录
环境与问题现象
- 运行环境:配备10G显存、40G虚拟硬盘的虚拟机
- 核心问题:FrankenPHP在高负载场景下会崩溃并自动退出,切换至官方最新v1.2.5版本后问题仍复现
- 崩溃后影响:SSH无法连接,仅能通过重启虚拟机恢复系统可用性
部署与启动命令
wget https://github.com/dunglas/frankenphp/releases/download/v1.2.5/frankenphp-linux-x86_64 sudo chmod 777 ./frankenphp-linux-x86_64 sudo ./frankenphp-linux-x86_64 run --config caddyfile
尝试的自动重启脚本
free_mem=800001 while [ $free_mem -gt 800000 ] do free_mem=$(cat /proc/meminfo | grep '^MemAvailable' | awk '{ print $2 }') echo "Free_mem:"$free_mem while [ $free_mem -lt 800000 ] do break 3 done ./frankenphp-linux-x86_64 run --config caddyfile done
注:原脚本存在语法错误,已修正
free_mem赋值方式为标准命令替换格式
迁移背景与兼容性怀疑
- 从ATS迁移至FrankenPHP,PHP源码未做任何修改
- 使用PHProxy代理技术,PHP以源码形式运行无需编译,不清楚其依赖的系统库,怀疑该代理项目与FrankenPHP存在兼容性冲突
静态构建Dockerfile
FROM dunglas/frankenphp:static-builder # Copy your app WORKDIR /go/src/app/dist/app COPY . . # Build the static binary WORKDIR /go/src/app/dist/app RUN rm -r dist/static-php-cli/watcher RUN EMBED=dist/app/ . /build-static.sh
Caddyfile配置
{ frankenphp order php_server before file_server } # Website root directory (adjust path as needed) :80 { # Enable compression encode zstd br gzip # PHP program location, here please modify according to the actual root directory root * /tmp/frankenphp_1b73543cc848c8af8018b0cb0a54feee/public/ # Return to empty page @blank path_regexp blank ^//blank/|^/blank/|^/favicon\.ico$ route @blank { header Access-Control-Allow-Origin "*" header Cache-Control "public, max-age=31536000" respond "" 200 abort } # Access the resource cache file directly @f1 path_regexp f1 ^/files/(\w)(\w\w)(\w{13})-\w-[\w\-]+(\.\w{2,4})$ route @f1 { rewrite /temp/{http.regexp.f1.1}/{http.regexp.f1.2}/{http.regexp.f1.1}{http.regexp.f1.2}{http.regexp.f1.3}{http.regexp.f1.4} } @f2 path_regexp f2 ^/files/\w/\w{10}(\w)(\w\w)(\w{13})\w{6}/[\w/]+(\.\w{2,4})$ route @f2 { rewrite /temp/{http.regexp.f2.1}/{http.regexp.f2.2}/{http.regexp.f2.1}{http.regexp.f2.2}{http.regexp.f2.3}{http.regexp.f2.4} } @tempfiles { path_regexp tempfiles ^/temp/\w/\w\w/\w{16}\.\w{2,4}$ } route @tempfiles { # Don't process any content, pass directly to static file file_server abort } # If no matching file or directory is found, pass to unified entry @notFound { not file } route @notFound { rewrite /index.php?__nonematch__=1 } # Forbidden directories or files @forbidden { not { path /robots.txt } path_regexp forbidden ^/(data|include|temp|plugin)/|\.db$|\.htaccess$|~\w+$|\.bak$|\.inc$|\.sh$|\.yaml$|\.ini$|\.bat$|\.dat$|\.txt$|\.lock$|\.conf$|\.inc\.php$|^/images/enc\.js$ } respond @forbidden "" 404 # PHP server php_server }
注:原Caddyfile存在重复定义
@forbidden的语法错误,已修正并统一规则
内容的提问来源于stack exchange,提问作者Li Li
相关产品推荐
相关产品推荐

