Quick answer
File at least 72 hours before departure as the authorities advise, and in practice one to two weeks ahead: if something is wrong or extra documents are requested, you still have time to fix it. Never apply after boarding or once already in Korea — it can cost you the trip.
