FrankenPHP crashes on high loads
FrankenPHP in a VM ,10G Vram ,40G VHD,crashes.
The problem is that it Crashed will automatically exit, Need to set up automatic restart.and the same happens when you switch to the latest official version 1.2.5. That is:
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
SSH Unable to connect.
reboot OK
We ported from ATS to FrankenPHP, the PHP source code remains the same, and we use the same basic techniques for PHP proxies and online programs such as :
https://en.wikipedia.org/wiki/PHProxy
https://github.com/PHProxy/phproxy
Exemple de site web pour la candidature :
Since the PHP program is raw code, it is not compiled, and the library used by the PHP environment is not known, and the PHP programmer does not care. Just like writing a web page in Notepad, you don’t have to worry about the technology used by the web server. Testing for compatibility with the proxy project mentioned above might also solve this problem.
Dockerfile for shenzhou-app’s static-build.
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
Translated with DeepL.com (free version)
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)(ww)(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)(ww)(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 {
path_regexp tempfiles ^/temp/w/ww/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 {
__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
}
3
Answers
Now frankenphp test application is the latest version 1.4.0, the solution to the “Segmentation fault” is that the PHP programmer found that the original PHP agent may be based on single-threaded design, frankenphp is currently a multi-threaded execution environment. Through num_threads 1 solved the problem. It seems that there is still a lot of room for improvement. If you set up Caddyfile to only use single threads, you won't get the segment error. You can use it this way for now, and then enable multithreading if the problem is solved. To modify it, add num_threads 1 under frankenphp {, and the modified code will look like this
Find a public program:
link
Such a proxy may be easy to find the problem. I use the zip package downloaded from the above project, directly extracted to the WEB working directory of the test frankenphp, replace the working file, that is, the frankenphp server has not changed, but the server web page has changed. When the agent has a dynamic web page with video, no matter what version, the package change 1.4.0 version, must be "Segmentation fault" exit.
But according to the method found by PHP programmers over here, once you set only single thread in Caddyfile, i.e. set "num_threads 1", there is a high probability that "Segmentation fault" will not occur, and it is possible to use this github project from the present! frankenphp problem solution.
Thanks Ulrich Eckhardt. Yes, the github project linked above is a minimal example of the current Segmentation fault problem. We were stuck with this problem for a long time because we didn’t know why the Segmentation fault exited, and we tried a lot of things, including adding a loop body, but it didn’t work, and the page provided to the user had to be refreshed several times before it finished loading, which was a very bad experience for the user.
After enabling the single-threaded solution, I can leave the loop body, and the page will be loaded at once. Although it may not be the optimal method, can also use frankenphp have Segmentation fault this error PHP project reference.
“ Whether it should be used do not understand, if there is something wrong, please directly help to change it to the correct one, thank you.