worker和swoole直接常驻内存运行抛弃fpm直接高效运行, 官方提供了现成的静态编译php文件,拿来直接可以运行,不用再自己吭哧吭哧再去编译,直接带上nginx就可以跑,如果将php打包成二进制文件会更简单。
几个相关项目发布地址
https://github.com/swoole/swoole-cli/releases
https://github.com/dixyes/phpmicro
https://github.com/crazywhalecc/static-php-cli
https://www.swoole.com/download
https://www.workerman.net/download
swoole-cli静态php
wget -O - https://github.com/swoole/swoole-cli/releases/download/v6.1.4.0/swoole-cli-v6.1.4-linux-x64.tar.xz | tar -xJ
install swoole-cli /usr/bin/swoole
workerman官方静态php
wget https://www.workerman.net/download/php/php-8.4-linux-x86_64.tar.gz| tar -xz
phpmicro可以打包php为二进制文件
apt update
apt install -y build-essential autoconf automake pkg-config libtool cmake clang -y
apt install -y php8.1-dev php8.4-cli php8.4-common -y
apt install -y libssl-dev libcurl4-openssl-dev libpq-dev libsqlite3-dev libzstd-dev libbrotli-dev liburing-dev libssl-dev -y
git clone https://github.com/swoole/swoole-src.git && cd swoole-src
/usr/bin/phpize8.4
./configure \
--with-php-config=/usr/bin/php-config8.4 \
--enable-swoole \
--enable-sockets \
--enable-mysqlnd \
--enable-swoole-curl \
--enable-swoole-pgsql \
--enable-swoole-sqlite \
--enable-swoole-stdext \
--enable-zstd \
--enable-brotli \
--enable-uring-socket
make && make install
echo extension=swoole.so >/etc/php/8.4/cli/conf.d/20-swoole.ini
systemctl服务
[Unit]
Description=Swoole HTTP Server
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
ExecStart=/usr/bin/php /opt/start.php start swoole
ExecReload=/bin/kill -USR1 $MAINPID
# 自动重启策略
Restart=always
RestartSec=3
# 防止僵尸进程
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=30
# 资源限制
LimitNOFILE=1048576
LimitNPROC=65535
# 日志
StandardOutput=journal
StandardError=journal
User=www-data
Group=www-data
[Install]
WantedBy=multi-user.target