---
title: "Khắc phục Timeout khi Build / Restore"
url: https://phatdev.net/docs/sl-migrations/how-to-handle-server-timeout-issues
lang: vi
updated: 2026-10-20
alternate:
  en: https://phatdev.net/en/docs/sl-migrations/how-to-handle-server-timeout-issues
markdown: https://phatdev.net/docs/sl-migrations/how-to-handle-server-timeout-issues.md
---

# Khắc phục Timeout khi Build / Restore

Thuộc bộ tài liệu: [SL Migrations](https://phatdev.net/docs/sl-migrations.md)

> Server timeout - build hoặc installer dừng giữa chừng.

## Server Timeout Issues

Triệu chứng: Build chạy 30-60 giây rồi dừng, hoặc installer step 1-3 báo `504 Gateway Timeout`.

## Nguyên nhân

Mỗi tầng trong stack có timeout riêng. Cần tăng tất cả các tầng phù hợp.

## Tầng PHP

Tăng các giá trị trong `php.ini` (hoặc `.user.ini` trong web root):

```ini
max_execution_time = 600
max_input_time = 600
memory_limit = 1024M
```

Sau khi sửa, reload PHP (nếu là VPS) hoặc đợi vài phút (nếu là shared hosting với .user.ini).

## Tầng web server (Nginx/Apache)

Web server cũng có timeout riêng cho request PHP.

**Nginx** - sửa `fastcgi_read_timeout` trong config:
```
fastcgi_read_timeout 600;
```

**Apache** - sửa `Timeout` trong config:
```
Timeout 600
```

Trên shared hosting, liên hệ support để tăng.

## Tầng CDN / Reverse Proxy

Nếu site dùng Cloudflare, hoặc proxy khác, các service này thường có timeout cứng (Cloudflare Free: 100s). Không thể tăng trên gói miễn phí.

**Workaround**: Tạm bypass CDN khi build/restore:
- Truy cập installer qua IP gốc + file `hosts` local
- Hoặc pause Cloudflare proxy (cloud icon → grey)

## Plugin tự chia chunk

Plugin tự động chia build/restore thành các chunk nhỏ, mỗi chunk xử lý trong giới hạn timeout an toàn rồi tự gọi chunk tiếp theo qua AJAX. Nếu plugin chunk đều mà vẫn timeout → AJAX request bị web server hoặc CDN cắt.

## Site rất lớn

Bản hiện tại không có lệnh WP-CLI để build. Với site rất lớn: giữ engine DupArchive (mặc định, build theo khối và tiếp tục được sau khi timeout), tăng timeout ở các tầng như trên, và xem [Two-Part Install](https://phatdev.net/docs/sl-migrations/two-part-install) để giải nén thủ công khi restore.

## Tham khảo

- [Server resources](https://phatdev.net/docs/sl-migrations/how-to-manage-server-resources-cpu-memory-disk)
- [Two-Part Install cho site lớn](https://phatdev.net/docs/sl-migrations/two-part-install)
