HTTP Error 500.0 - Internal Server Error FastCGI 進程超過了配置的活動超時時限 E:\PHP\php-cgi.exe
IIS FastCGI 設定的 `activityTimeout` (預設 70 秒) 短於 PHP 腳本實際執行時間 (大數據匯出、長時間計算、外部 API 呼叫等)。
# 查看目前設定 %windir%\system32\inetsrv\appcmd.exe list config /section:system.webServer/fastCgi # 修改 activityTimeout 為 600 秒 %windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/fastCgi "/[fullPath='E:\PHP\php-cgi.exe'].activityTimeout:600"
<?php
// 長時間任務:忽略用戶斷開、無時間限制
ignore_user_abort(true);
set_time_limit(0); // 0 = 無限制
// 分批處理大數據,避免記憶體耗盡
foreach ($largeDataset as $batch) {
processBatch($batch);
// 定期輸出進度,防止 FastCGI 以為掛起
echo "Processed " . count($batch) . " records\n";
flush();
// 釋放記憶體
gc_collect_cycles();
}
?>