perf: optimization php config (#9321)

This commit is contained in:
CityFun 2025-06-27 16:56:13 +08:00 committed by GitHub
parent 315f99a03a
commit 64fd715973
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 48 additions and 3 deletions

View file

@ -1003,3 +1003,23 @@ func handlePHPDir(runtime model.Runtime) {
_ = fileOp.ChownR(dir, strconv.Itoa(1000), strconv.Itoa(1000), true)
}
}
func HandleOldPHPRuntime() {
runtimes, _ := runtimeRepo.List(repo.WithByType(constant.RuntimePHP))
if len(runtimes) == 0 {
return
}
fileOp := files.NewFileOp()
for _, runtime := range runtimes {
composePtah := runtime.GetComposePath()
composeBytes, _ := fileOp.GetContent(composePtah)
composeContent := strings.ReplaceAll(string(composeBytes), "./conf:/usr/local/etc/php", "./conf/php.ini:/usr/local/etc/php/php.ini")
composeContent = strings.ReplaceAll(composeContent, "./conf/php-fpm.conf:/usr/local/etc/php-fpm.d/www.conf", "./conf/php-fpm.conf:/usr/local/etc/php-fpm.conf")
composeContent = strings.ReplaceAll(composeContent, "./extensions:${EXTENSION_DIR}", "./extensions:/usr/local/lib/php/extensions")
_ = fileOp.WriteFile(composePtah, strings.NewReader(composeContent), constant.DirPerm)
_ = fileOp.WriteFile(runtime.GetFPMPath(), bytes.NewReader(nginx_conf.GetWebsiteFile("php-fpm.conf")), constant.DirPerm)
go func() {
_ = restartRuntime(&runtime)
}()
}
}

View file

@ -0,0 +1,16 @@
[global]
error_log = /var/log/php/fpm.error.log
log_level = notice
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /status
slowlog = /var/log/php/fpm.slow.log
request_slowlog_timeout = 3
catch_workers_output = yes

View file

@ -41,11 +41,11 @@ var RuntimeDefaultVolumes = map[string]string{
var PHPDefaultVolumes = map[string]string{
"${PANEL_WEBSITE_DIR}": "/www/",
"./conf": "/usr/local/etc/php",
"./conf/php.ini": "/usr/local/etc/php/php.ini",
"./conf/conf.d": "/usr/local/etc/php/conf.d",
"./conf/php-fpm.conf": "/usr/local/etc/php-fpm.d/www.conf",
"./conf/php-fpm.conf": "/usr/local/etc/php-fpm.conf",
"./log": "/var/log/php",
"./extensions": "${EXTENSION_DIR}",
"./extensions": "/usr/local/lib/php/extensions",
"./supervisor/supervisord.conf": "/etc/supervisord.conf",
"./supervisor/supervisor.d/php-fpm.ini": "/etc/supervisor.d/php-fpm.ini",
"./supervisor/supervisor.d": "/etc/supervisor.d",

View file

@ -26,6 +26,7 @@ func InitAgentDB() {
migrations.UpdateWebsiteExpireDate,
migrations.UpdateRuntime,
migrations.AddSnapshotRule,
migrations.UpdatePHPRuntime,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View file

@ -332,3 +332,11 @@ var AddSnapshotRule = &gormigrate.Migration{
)
},
}
var UpdatePHPRuntime = &gormigrate.Migration{
ID: "20250624-update-php-runtime",
Migrate: func(tx *gorm.DB) error {
service.HandleOldPHPRuntime()
return nil
},
}