Skip to content

Commit e0ea28f

Browse files
CopilotPDowney
andcommitted
fix: rename variable, remove dead code, consolidate CPU branches, add memory threshold constants in php-config-update.sh
Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/58f0a3ef-e965-42d5-bd35-88a5eda8fb5d Co-authored-by: PDowney <[email protected]>
1 parent 555764d commit e0ea28f

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to EngineScript will be documented in this file.
44

55
Changes are organized by date, with the most recent changes listed first.
66

7+
## 2026-03-31
8+
9+
### 🔧 PHP-CONFIG-UPDATE.SH CODE QUALITY IMPROVEMENTS
10+
11+
- **Renamed variable** `AVERAGE_PHP_MEMORY_REQ` to `AVERAGE_PHP_MEMORY_REQ_MB` in `scripts/update/php-config-update.sh` with a clarifying comment to indicate the value is in megabytes.
12+
- **Removed commented-out dead code** (obsolete alternative calculations) and replaced with a descriptive comment clarifying the intent.
13+
- **Consolidated duplicate CPU_COUNT branches** for values 3 and 4 into a single range check (`-ge 3 && -le 4`) to reduce code duplication.
14+
- **Introduced named memory threshold constants** (`MEMORY_THRESHOLD_LOW`, `MEMORY_THRESHOLD_MEDIUM`, `MEMORY_THRESHOLD_HIGH`) to replace magic numbers 1200, 2200, and 4200 in memory-based conditionals.
15+
716
## 2026-03-27
817

918
### 🐛 DEBUG MODE ADDED TO ALL INSTALL AND UPDATE SCRIPTS

scripts/update/php-config-update.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ calculate_php() {
2323
# No fallbacks needed as this script will be run on a system with a modern kernel.
2424
# MemAvailable field will be present in /proc/meminfo on modern kernels and is the most accurate representation of available memory for applications.
2525
AVAILABLE_MEMORY=$(awk '/MemAvailable/ {printf "%d", $2/1024}' /proc/meminfo)
26-
AVERAGE_PHP_MEMORY_REQ=80
26+
AVERAGE_PHP_MEMORY_REQ_MB=80 # average PHP memory requirement in MB
2727
CPU_COUNT="$(nproc --all)" # Get the number of CPU threads
28-
#PHP_FPM_MAX_CHILDREN_ALT=$((AVAILABLE_MEMORY/AVERAGE_PHP_MEMORY_REQ))
29-
#PHP_FPM_MAX_CHILDREN=$(( "$(free -m | awk 'NR==2{printf "%d", $2/80 }')" ))
30-
#SERVER_MEMORY_TOTAL_01="$(free -m | awk 'NR==2{printf "%d", $2*0.01 }')"
31-
#SERVER_MEMORY_TOTAL_03=$(( "$(free -m | awk 'NR==2{printf "%d", $2*0.03 }')" ))
32-
#SERVER_MEMORY_TOTAL_13=$(( "$(free -m | awk 'NR==2{printf "%d", $2*0.13 }')" ))
33-
#SERVER_MEMORY_TOTAL_100="$(free -m | awk 'NR==2{printf "%d", $2 }')"
28+
# Memory thresholds in MB for tuning PHP-FPM and PHP settings
29+
MEMORY_THRESHOLD_LOW=1200
30+
MEMORY_THRESHOLD_MEDIUM=2200
31+
MEMORY_THRESHOLD_HIGH=4200
32+
# PHP-FPM process limits are tuned using available memory and average per-process usage.
3433

3534
# Dynamically calculate pm.start_servers, pm.min_spare_servers, and pm.max_spare_servers based on CPU threads
3635
if [[ "${CPU_COUNT}" -eq 1 ]]; then
@@ -41,11 +40,7 @@ calculate_php() {
4140
PHP_FPM_START_SERVERS=3
4241
PHP_FPM_MIN_SPARE_SERVERS=2
4342
PHP_FPM_MAX_SPARE_SERVERS=5
44-
elif [[ "${CPU_COUNT}" -eq 3 ]]; then
45-
PHP_FPM_START_SERVERS=4
46-
PHP_FPM_MIN_SPARE_SERVERS=3
47-
PHP_FPM_MAX_SPARE_SERVERS=6
48-
elif [[ "${CPU_COUNT}" -eq 4 ]]; then
43+
elif [[ "${CPU_COUNT}" -ge 3 && "${CPU_COUNT}" -le 4 ]]; then
4944
PHP_FPM_START_SERVERS=4
5045
PHP_FPM_MIN_SPARE_SERVERS=3
5146
PHP_FPM_MAX_SPARE_SERVERS=6
@@ -64,17 +59,17 @@ calculate_php() {
6459
fi
6560

6661
# Calculate pm.max_children based on available memory
67-
if [[ "${AVAILABLE_MEMORY}" -lt 1200 ]]; then
62+
if [[ "${AVAILABLE_MEMORY}" -lt "${MEMORY_THRESHOLD_LOW}" ]]; then
6863
PHP_FPM_MAX_CHILDREN=8
6964
PHP_MEMORY_LIMIT="256M"
7065
OPCACHE_JIT_BUFFER="64M"
7166
OPCACHE_INT_BUFFER=16
72-
elif [[ "${AVAILABLE_MEMORY}" -lt 2200 ]]; then
67+
elif [[ "${AVAILABLE_MEMORY}" -lt "${MEMORY_THRESHOLD_MEDIUM}" ]]; then
7368
PHP_FPM_MAX_CHILDREN=16
7469
PHP_MEMORY_LIMIT="256M"
7570
OPCACHE_JIT_BUFFER="64M"
7671
OPCACHE_INT_BUFFER=16
77-
elif [[ "${AVAILABLE_MEMORY}" -lt 4200 ]]; then
72+
elif [[ "${AVAILABLE_MEMORY}" -lt "${MEMORY_THRESHOLD_HIGH}" ]]; then
7873
PHP_FPM_MAX_CHILDREN=24
7974
PHP_MEMORY_LIMIT="512M"
8075
OPCACHE_JIT_BUFFER="96M"

0 commit comments

Comments
 (0)