Cron in PrestaShop: scheduled tasks done right
Subscriptions, Google feeds, ERP synchronisation: many things depend on a cron job. We show you how to set them up so they do not fail silently.
Many store functions are not triggered by a customer but by the clock: charging subscription renewals, regenerating the Google Shopping feed, synchronising stock with the ERP, cleaning up carts. That is what cron tasks are for.
Two ways to run them
By URL
*/15 * * * * curl -s "https://tienda.com/module/mimodulo/cron?token=XXXX" > /dev/null
Simple and works on any hosting, but the task is subject to the web server's limits (execution time, page cache, firewall).
From the command line
*/15 * * * * cd /var/www/tienda && php modules/mimodulo/cron.php >> var/logs/cron-mimodulo.log 2>&1
No web server limits and its own log. It is the preferable option when you have SSH.
Security
- Every cron URL must carry a long, random token and check it before doing anything.
- Never put the token in a public link or in the robots.txt.
- If the task takes payments or sends emails, make it idempotent: running it twice must not charge twice.
Do not let them fail silently
- Keep a log with the date, what it did and how long it took.
- Store the date of the last successful run and show it in the module's back office.
- Send an alert (email, Telegram, Slack) if a critical task has gone too long without running.
Reasonable frequencies
| Task | Frequency |
|---|---|
| Subscription renewals | Once or several times a day |
| Stock synchronisation | Every 5–15 minutes |
| Product feeds | Once a day |
| Data clean-up | Once a week or once a month |