# Cron 설정하기

Hotopay의 Cron 기능은 정기 결제를 위해 제작되었습니다.

정기결제, 해외 환율 동기화 및 Cron이 필요한 Hotopay 서드파티를 사용하지 않으신다면 이 단계를 넘기셔도 됩니다.

Rhymix 2.1 이상, PHP 7.4 이상, Linux crontab 기능을 요구합니다.

### Cron에서 진행하는 작업 목록

* 3일 이상 경과한 결제건 자동 취소
* 최신 환율 적용
* 정기결제 처리
* Hotopay cron과 연결된 서드파티 동작 수행

### Cron 설정하기

Hotopay Cron은 최소 1시간, 최대 1일 간격으로 호출하도록 권장합니다.

또한 Cron 실행 권한은 웹 실행 권한과 동일해야합니다. 동일하지 않을경우 Cron이 실행되지 않습니다.

너무 잦은 실행은 로그 저장 부담이 있을 수 있으니 상황에 맞춰 적절하게 적용해주세요.

```sh
# 매 1시간마다 (정기결제 건이 많을경우 권장)
0 * * * * cd /[라이믹스 루트]/modules/hotopay && php hotopay.cron.php > /[로그 저장 루트]/hotopay_cron_$(date +\%Y\%m\%d_\%H\%M\%S).log 2>&1

# 매 3시간마다 (일반적으로 권장)
0 */3 * * cd /[라이믹스 루트]/modules/hotopay && php hotopay.cron.php > /[로그 저장 루트]/hotopay_cron_$(date +\%Y\%m\%d_\%H\%M\%S).log 2>&1

# 매일 오전 11시마다
0 11 * * * cd /[라이믹스 루트]/modules/hotopay && php hotopay.cron.php > /[로그 저장 루트]/hotopay_cron_$(date +\%Y\%m\%d_\%H\%M\%S).log 2>&1
```

로그 저장 루트는 웹에서 접근할 수 없는 위치에 저장해주세요.

### Cron 실행 권한과 웹 실행 권한이 다른 경우

만약 리눅스에서 sudo를 사용할 수 있는경우 다음과 같은 방식으로 crontab을 설정해주세요.

```sh
# 웹 실행 유저가 www-data일 경우
0 * * * * cd /[라이믹스 루트]/modules/hotopay && sudo -u www-data php hotopay.cron.php > /[로그 저장 루트]/hotopay_cron_$(date +\%Y\%m\%d_\%H\%M\%S).log 2>&1
```

해당 코드는 보안 이슈를 막기 위해 실행 권한을 제어하고 있으며, 임의로 별도의 권한에서도 작동할 수 있도록 개조할 경우 모든 책임은 자신에게 있음을 명심해주세요.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hotopaydocs.potatosoft.kr/cron.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
