← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Cron Jobs

Linux PHP 5.0+ Beginner
debt(d7/e3/b5/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). Cron job misconfigurations (wrong PATH, missing output redirect, overlapping executions) are not caught by any automated tool in the detection_hints — tools like crontab, crunz, and laravel-scheduler are management tools, not static analyzers. Problems surface only when jobs silently fail in production or overlap, requiring manual review or runtime observation to detect.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix suggests straightforward fixes: add MAILTO='', redirect output to log files, use absolute paths. Each fix is localized to the crontab or job script. However, retrofitting overlap prevention (file locking) or switching to a scheduler framework touches multiple files, pushing slightly above e1.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). Cron jobs apply only to CLI context but affect ongoing operations: every new scheduled task must follow the same conventions (absolute paths, logging, locking). A poorly designed cron setup decays over time as jobs accumulate without monitoring. It's not architectural-level burden but imposes a persistent operational tax on the team.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception explicitly states developers assume cron runs in the same environment as their shell — it doesn't. This contradicts how interactive shells work, where relative paths and typical PATH settings function normally. The 'obvious' way (using 'php script.php' without absolute paths) fails silently, matching t7's 'contradicts how a similar concept works elsewhere.'

About DEBT scoring →

Also Known As

crontab scheduled tasks cron

TL;DR

Scheduled tasks defined in a crontab file, executing commands at specified time intervals — from once a minute to once a year.

Explanation

Cron syntax: five fields (minute hour day month weekday) followed by the command. Special strings (@hourly, @daily, @weekly, @monthly, @reboot) simplify common schedules. Cron runs in a minimal environment — PATH is different from interactive shells, so use absolute paths. Output goes to the user's email unless redirected. PHP cron jobs should use the CLI SAPI, not the web server. Consider systemd timers or a task scheduler like Laravel Scheduler for more complex needs.

Diagram

flowchart LR
    CRON[cron daemon] -->|reads| CRONTAB[crontab -e]
    CRONTAB --> SYNTAX[minute hour day month weekday command]
    subgraph Examples
        EV_MIN[every minute: * * * * *]
        EV_HOUR[every hour: 0 * * * *]
        EV_DAY[daily 2am: 0 2 * * *]
        EV_WEEK[weekly Mon: 0 0 * * 1]
    end
    CRON --> EXEC[Execute command]
    EXEC -->|stdout| MAIL[Email to user<br/>or redirect to log]
    subgraph Issues
        OVERLAP[Job overlaps<br/>previous still running]
        ENV2[Wrong environment<br/>PATH not set]
        OVERLAP & ENV2 -->|fix with| LOCKFILE[flock or systemd timers]
    end
style EXEC fill:#238636,color:#fff
style OVERLAP fill:#f85149,color:#fff
style LOCKFILE fill:#1f6feb,color:#fff

Common Misconception

Cron runs in the same environment as your shell — cron has a minimal PATH; always use absolute paths to binaries and PHP.

Why It Matters

Misconfigured cron jobs silently fail or run as the wrong user — a missed database cleanup or report generation creates data accumulation or business problems.

Common Mistakes

  • Using relative paths — cron's PATH does not include /usr/local/bin; use /usr/bin/php explicitly.
  • Not redirecting output — all stdout/stderr goes to cron email which is often unmonitored.
  • Overlapping executions — a slow job runs again before the previous one completes; use file locking.
  • Running cron jobs as root when a less privileged user is sufficient.

Code Examples

✗ Vulnerable
# Broken cron — relative path, no output handling:
*/5 * * * * php /var/www/app/artisan schedule:run
# Fails silently: 'php' not found in cron PATH
# No output captured — errors invisible
✓ Fixed
# Correct cron entry:
*/5 * * * * /usr/bin/php /var/www/app/artisan schedule:run \
    >> /var/log/app/schedule.log 2>&1

# With flock to prevent overlap:
*/5 * * * * flock -n /tmp/schedule.lock \
    /usr/bin/php /var/www/app/artisan schedule:run >> /var/log/app/schedule.log 2>&1

Added 15 Mar 2026
Edited 22 Mar 2026
Views 61
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 2 pings S 4 pings M 1 ping T 2 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 8 Perplexity 7 Scrapy 7 Google 6 Ahrefs 4 SEMrush 4 ChatGPT 3 Unknown AI 2 Bing 2 Claude 1 Meta AI 1 Majestic 1 PetalBot 1
crawler 42 crawler_json 5
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Add MAILTO='' at the top of your crontab to suppress email on success; log all output to a file; use a cron management tool (Crunz, Laravel Scheduler) for complex schedules
📦 Applies To
PHP 5.0+ cli laravel symfony
🔗 Prerequisites
🔍 Detection Hints
No output logging from cron jobs; cron running as root; no overlap prevention for long-running jobs; no alerting on cron failure
Auto-detectable: ✗ No crontab crunz laravel-scheduler
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File
CWE-732


✓ schema.org compliant