In this article · 7 sections
Cron jobs run commands automatically on a schedule: send booking reminders every morning, clean old sessions every night, generate a sitemap weekly, back up the database daily. Most hosting panels, including Hostinger hPanel and cPanel, let you set them up without server access.
Cron syntax
* * * * * command
│ │ │ │ │
│ │ │ │ └── day of week (0–7, Sunday = 0 or 7)
│ │ │ └──── month (1–12)
│ │ └────── day of month (1–31)
│ └──────── hour (0–23)
└────────── minute (0–59)
Common schedules
| Schedule | Expression |
|---|---|
| Every 15 minutes | */15 * * * * |
| Every day at 2:30 AM | 30 2 * * * |
| Every Monday at 9 AM | 0 9 * * 1 |
| First day of each month | 0 6 1 * * |
Server time may be UTC rather than IST (IST = UTC + 5:30). Check your host's timezone before choosing times.
Example: daily reminder emails
cron/reminders.php:
<?php
if (PHP_SAPI !== 'cli') { http_response_code(403); exit; } // run only from cron
require __DIR__ . '/../connection.php';
$res = $conn->query("SELECT id, name, phone FROM bookings
WHERE travel_date = CURDATE() + INTERVAL 1 DAY AND status = 'confirmed'");
while ($b = $res->fetch_assoc()) {
// send reminder by email/SMS/WhatsApp API…
}
echo date('c') . " reminders done\n";
Setting it up
Hostinger hPanel: Advanced → Cron Jobs → choose "PHP" or "Custom", enter the script path and schedule.
cPanel: Advanced → Cron Jobs → add a command like:
/usr/local/bin/php /home/USERNAME/public_html/cron/reminders.php >> /home/USERNAME/cron.log 2>&1
The PHP path differs between hosts; your panel usually shows it.
Good practices
- Keep cron scripts outside the public folder, or block web access (as in the
PHP_SAPIcheck above) - Log output to a file so you can see whether it ran
- Prevent overlap for long tasks using a lock file:
<?php
$lock = fopen(__DIR__ . '/reminders.lock', 'c');
if (!flock($lock, LOCK_EX | LOCK_NB)) exit("Already running\n");
- Don't schedule heavy jobs every minute on shared hosting
- Send yourself an alert if an important job fails
Ideas for business websites
- Daily database backup to cloud storage. See website backups
- Booking and payment reminders
- Delete old uploads and logs. See DPDP basics
- Regenerate sitemaps and cache
FAQs
My cron job doesn't run. Why?
Wrong PHP path, wrong file path (use absolute paths), or a PHP error. Check the log file.
Can I trigger a URL instead?
Yes, with curl or wget, but protect that URL with a secret key.
Was this article helpful?
Your answer helps us improve our guides