# keepalive-nextcloud.ps1 # 每 30s 一次 curl https://127.0.0.1:14443/status.php # 目的:让 PHP-CGI 4 worker 永远保持热,避免公网 nc.gvsds.com 第一次 60-90s cold start 撞 frpc 60s 超时 # 用法:Start-Process powershell -WindowStyle Hidden -FilePath D:\SMANAGE\php\keepalive-nextcloud.ps1 # 停止:Stop-Process -Name powershell -Filter "CommandLine -like 'keepalive-nextcloud*'" $ErrorActionPreference = 'SilentlyContinue' $url = 'https://127.0.0.1:14443/status.php' $intervalSec = 30 $logDir = 'D:\SMANAGE\logs' if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null } $logFile = Join-Path $logDir 'keepalive-nextcloud.log' function Log($msg) { $ts = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' "$ts $msg" | Out-File -FilePath $logFile -Append -Encoding UTF8 } Log '=== keepalive-nextcloud 启动 ===' Log "target: $url interval: ${intervalSec}s" # 让 curl 跳过证书验证(自签/通配证书) $env:CURL_CA_BUNDLE = '' $skipCert = '-k' while ($true) { $sw = [System.Diagnostics.Stopwatch]::StartNew() $out = & curl.exe $skipCert -s -o $null --max-time 60 -w 'code=%{http_code} time=%{time_total}s' $url 2>&1 $sw.Stop() $ms = [int]$sw.ElapsedMilliseconds if ($ms -gt 1500 -or $LASTEXITCODE -ne 0) { Log " SLOW/FAIL $out wall=${ms}ms exit=$LASTEXITCODE" } Start-Sleep -Seconds $intervalSec }