CRON jobs
How to run a bulk translation job on your server with a scheduled task, so it does not depend on your browser or on the time limit of a web request.
When to use a CRON job
A bulk translation of a large catalogue can take hours. Started from the browser, it runs inside one web request, and many servers stop web requests after a few minutes (the PHP setting max_execution_time). A CRON job runs the translation from the server itself, where this limit usually does not apply or is much higher.
Getting the commands
- Create the job in Content translations.
- In My translations, press CRON in the row of the job. The CRON Job Configuration window opens.
- The window shows two ways to run that job, already filled in with the exact path and address of the CRON file in your store, the job ID and the CRON key of your store:
| Method | What it runs |
|---|---|
| Method 1: Direct PHP Execution | The PHP file of the extension, run by the PHP of your server. Use this one if your hosting lets you run PHP commands in CRON jobs. |
| Method 2: Using URL with WGET or CURL | The same file called through its web address. Use it if your hosting only allows CRON jobs that open a URL. |
They look like this, with your own path, domain, job ID and key:
php /home/youraccount/public_html/admin/controller/extension/module/ai_translator_pro/ai_translator_pro_cron.php action=start_translation translation_id=12 key=YOUR_CRON_KEYhttps://www.your-store.com/admin/controller/extension/module/ai_translator_pro/ai_translator_pro_cron.php?action=start_translation&translation_id=12&key=YOUR_CRON_KEYThe window always shows the real location of the file, also when your administration folder has another name and on OpenCart 2.0.x to 2.2.x, where the file is admin/controller/module/ai_translator_pro_cron.php. Copy the commands from the window instead of writing them by hand.
The CRON key
A CRON job runs without an administrator logged in, so the extension checks the key at the end of the command instead. The key is created the first time you open the module and is the same for every job of your store. It is kept when you save the settings or update the extension.
- A command without the key stops with Error: "key" param not found. and does nothing.
- A command with a wrong key stops with Invalid CRON key. and does nothing.
Creating the CRON job
Create a new CRON job in the control panel of your hosting (often called "Cron Jobs" or "Scheduled Tasks") and paste one of the example lines of the window as the command. They look like this:
* * * * * php PATH_TO_CRON_FILE action=start_translation translation_id=[TRANSLATION_ID] key=[CRON_KEY]* * * * * /usr/bin/wget -q -O /dev/null "[CRON_URL]"* * * * * /usr/bin/curl -s "[CRON_URL]" > /dev/null 2>&1In the window, PATH_TO_CRON_FILE, [TRANSLATION_ID], [CRON_KEY] and [CRON_URL] are already replaced with the values of your store and of the job. * * * * * runs the command every minute. Your hosting panel may ask for the schedule in separate fields; the command itself is the part after the five asterisks.
If the php command of your server is not found, ask your hosting provider for the full path of PHP (for example /usr/bin/php or /usr/local/bin/php).
What happens when the CRON job runs
Each run starts the job, exactly like the Start button, and translates its remaining fields until the job is completed. Follow the progress in My Translations.
- Only one job can translate at a time. While a job is running, a new run does not start a second one and answers Translations #N is running. with the number of the job that is translating.
- A job that runs out of tokens stops with the status Stopped. After you buy tokens, the next run continues it.
- Once the job is Completed, the next runs find nothing to translate.
When the job is completed, delete the CRON job from your hosting panel. Each CRON job runs one translation job, identified by its ID; for another job, change the ID or create a new CRON job.
Still need help?
Open a support ticket from your account and our team will look at your store with you.