fix: speed up local Docker PHP APIs

This commit is contained in:
hajimi
2026-08-01 16:18:19 +08:00
parent 42284ba6ac
commit 9a83c8dfb7
6 changed files with 84 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
FROM registry.cn-guangzhou.aliyuncs.com/likeadmin/php:8.0.30.3-fpm
RUN docker-php-ext-install -j"$(nproc)" opcache
COPY docker/config/php/conf.d/zz-opcache.ini /usr/local/etc/php/conf.d/zz-opcache.ini
+9
View File
@@ -0,0 +1,9 @@
; Keep source changes immediately visible while avoiding repeated PHP compilation.
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=0
opcache.save_comments=1
+8 -2
View File
@@ -1,8 +1,14 @@
name: sport-era-dev name: sport-era-dev
x-php-image: &php-image
image: sport-era-dev-php:local
build:
context: ..
dockerfile: docker/Dockerfile.php
services: services:
server: server:
image: registry.cn-guangzhou.aliyuncs.com/likeadmin/php:8.0.30.3-fpm <<: *php-image
working_dir: /likeadmin_php/server working_dir: /likeadmin_php/server
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
@@ -16,7 +22,7 @@ services:
- sport-era-dev - sport-era-dev
scheduler: scheduler:
image: registry.cn-guangzhou.aliyuncs.com/likeadmin/php:8.0.30.3-fpm <<: *php-image
working_dir: /likeadmin_php/server working_dir: /likeadmin_php/server
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
+18
View File
@@ -13,6 +13,24 @@
## 一、已完成事项 ## 一、已完成事项
### 92. 本地 Docker PHP 接口性能修复
- 状态:代码已修改,待重新构建容器并验证 - 时间:2026-08-01
完成内容:
- 本地 `server``scheduler` 统一改为由 `docker/Dockerfile.php` 构建的 `sport-era-dev-php:local` 镜像。
- PHP 镜像新增 OPcache,并保留 `validate_timestamps=1``revalidate_freq=0`,使开发环境在源码变更时立即失效缓存、请求间不再反复编译 PHP 文件。
- uni-app H5 本地接口地址由 `localhost:8000` 改为 `127.0.0.1:8000`,避免本机 `localhost` TCP 连接的额外延迟。
涉及模块:
- `docker/Dockerfile.php`
- `docker/config/php/conf.d/zz-opcache.ini`
- `docker/docker-compose.dev.yml`
- `uniapp/src/config/index.ts`
验证说明:
- 配置静态检查已覆盖 OPcache 构建与配置、H5 IPv4 回环地址;运行时验证需重新构建 PHP 镜像后执行。
### 91. 赛事 Tab 默认主页 ### 91. 赛事 Tab 默认主页
- 状态:已完成 - 时间:2026-08-01 - 状态:已完成 - 时间:2026-08-01
@@ -0,0 +1,43 @@
<?php
$root = dirname(__DIR__, 2);
$files = [
'compose' => $root . '/docker/docker-compose.dev.yml',
'php_dockerfile' => $root . '/docker/Dockerfile.php',
'opcache_ini' => $root . '/docker/config/php/conf.d/zz-opcache.ini',
'uniapp_config' => $root . '/uniapp/src/config/index.ts',
];
foreach ($files as $label => $path) {
if (!is_file($path)) {
fwrite(STDERR, "缺少性能配置文件: {$label} => {$path}\n");
exit(1);
}
}
$compose = file_get_contents($files['compose']);
$dockerfile = file_get_contents($files['php_dockerfile']);
$opcacheIni = file_get_contents($files['opcache_ini']);
$uniappConfig = file_get_contents($files['uniapp_config']);
$expectations = [
[$compose, 'sport-era-dev-php:local', 'server 和 scheduler 应使用本地 PHP 镜像'],
[$compose, 'docker/Dockerfile.php', '本地 PHP 镜像应由 Dockerfile 构建'],
[$dockerfile, 'docker-php-ext-install', '本地 PHP 镜像必须安装 OPcache'],
[$dockerfile, 'opcache', '本地 PHP 镜像必须安装 OPcache'],
[$dockerfile, 'zz-opcache.ini', '本地 PHP 镜像必须载入 OPcache 配置'],
[$opcacheIni, 'opcache.enable=1', 'OPcache 必须启用'],
[$opcacheIni, 'opcache.validate_timestamps=1', '开发环境必须保留源码更新时间检测'],
[$opcacheIni, 'opcache.revalidate_freq=0', '源码修改必须立即使 OPcache 失效'],
[$uniappConfig, 'http://127.0.0.1:8000', 'H5 本地 API 应使用 IPv4 回环地址'],
];
foreach ($expectations as [$haystack, $needle, $message]) {
if (strpos($haystack, $needle) === false) {
fwrite(STDERR, $message . "\n");
exit(1);
}
}
echo "本地 Docker PHP 性能配置静态检查通过\n";
+1 -1
View File
@@ -1,5 +1,5 @@
// const envBaseUrl = 'https://test-server.sbnews.net/' // const envBaseUrl = 'https://test-server.sbnews.net/'
const envBaseUrl = 'http://localhost:8000' const envBaseUrl = 'http://127.0.0.1:8000'
let baseUrl = `${envBaseUrl}/` let baseUrl = `${envBaseUrl}/`