Skip to main content

Cron Jobs & Scheduled Tasks

The platform relies heavily on server-level cron jobs (not WordPress wp-cron) to perform automated maintenance, monitoring, and synchronization tasks. All cron scripts are located in Z:\Herd\manage\cron/.


Cron Architecture

Execution Method

All scripts are executed via server crontab as direct PHP processes:

# Example crontab entry
*/5 * * * * /usr/bin/php /path/to/manage/cron/site-updates.php >> /var/log/cron.log 2>&1

Each script bootstraps WordPress at the top:

<?php
// Bootstrap WordPress
require_once dirname(__DIR__) . '/wp-load.php';

// Script logic...

Why Server Cron (Not WP-Cron)

  • Reliability: Server cron runs on schedule regardless of site traffic
  • Long-running tasks: Some scripts take 10+ minutes (Harvest sync)
  • Rate limiting: Scripts need precise timing for API delays
  • No duplicate execution: Server cron prevents overlapping runs

Site Update Scripts

site-updates.php

Schedule: Every 5 minutes
Purpose: Processes the site update queue, syncing site data in batches.

Behavior:

  1. Reads next 15 sites from suma_cron queue
  2. For each site, runs Site_Update class sync (MainWP data, SSL check, plugins, themes)
  3. Fires suma_site_updated hook (triggers Pinecone auto-sync)
  4. Removes processed entries from queue
  5. Exits when queue is empty or batch limit reached

Key Details:

  • Processes 15 sites per run to avoid timeouts
  • Full cycle of all sites takes approximately 4–6 hours
  • Sites are re-queued after full cycle completes

daily-site-check.php

Schedule: Daily (midnight)
Purpose: Comprehensive health check on all active sites.

Checks Performed:

  • SSL certificate expiration
  • Google indexing status
  • WordPress version currency
  • Plugin update availability
  • Debug mode status
  • WP-Cron functionality
  • Missing H1 tags
  • Contact page accessibility

update-servers.php

Schedule: Daily
Purpose: Syncs WP Engine server data via their REST API.

Behavior:

  1. Calls WP Engine API v0 for account installs
  2. Updates suma_wpengine table with PHP version, environment, domains
  3. Updates suma_server_domain_mapping table

Monitoring Scripts

uptime-robot.php

Schedule: Every 15 minutes
Purpose: Syncs UptimeRobot monitoring data for all managed sites.

Behavior:

  1. Queries UptimeRobot API for all monitors
  2. Updates suma_sites.uptime field with current status
  3. Logs any newly-detected downtime events

jetpack-protect.php

Schedule: Daily
Purpose: Fetches vulnerability data from Jetpack Protect API.

Behavior:

  1. Queries Jetpack vulnerability feed for all WordPress sites
  2. Updates suma_vulnerabilities master table
  3. Updates suma_vulnerabilities_site linking table
  4. Flags any new critical vulnerabilities

Reporting Scripts

daily-git-reports.php

Schedule: Daily (morning)
Purpose: Generates developer commit activity reports from Bitbucket.

Behavior:

  1. Queries Bitbucket API for recent commits across all repositories
  2. Updates suma_git_status table with developer activity
  3. Generates summary for management review

daily-disconnected-report.php

Schedule: Daily
Purpose: Reports on MainWP child sites that have lost connection.

Behavior:

  1. Checks MainWP for sites with disconnected status
  2. Sends email report listing disconnected sites
  3. Triggers reconnection attempts for known-fixable cases

added-deleted-plugins-report.php

Schedule: Daily
Purpose: Reports on plugin changes across managed sites.

Behavior:

  1. Compares current plugin lists with previous day's snapshot
  2. Identifies newly added and removed plugins
  3. Sends email report to management

Schedule: Weekly
Purpose: Identifies paid plugins that are installed but deactivated.

Behavior:

  1. Cross-references suma_cost (paid plugins) with site plugin data
  2. Identifies inactive paid plugins that are costing money
  3. Generates report for cost optimization review

unlicensed-plugin.php

Schedule: Weekly
Purpose: Finds plugins that lack proper licensing.

Behavior:

  1. Scans all sites for plugins without license keys in suma_cost
  2. Reports premium plugins potentially running unlicensed
  3. Helps ensure compliance with plugin vendor terms

Harvest & Time Tracking Scripts

check-for-new-sheets-projects.php

Schedule: Daily
Purpose: Checks Google Sheets for new project entries and creates matching Harvest projects.

Behavior:

  1. Reads project management Google Sheet
  2. Identifies entries without corresponding Harvest projects
  3. Creates new Harvest projects via API
  4. Updates sheet with Harvest project links

google-sheet-feature-update.php

Schedule: Daily
Purpose: Syncs feature/task data between Google Sheets and the management platform.


Screenshot & Visual Scripts

generate_screenshots.php

Schedule: Weekly
Purpose: Orchestrates screenshot generation for all managed sites.


schedule-screenshots.php

Schedule: Triggered by generate_screenshots
Purpose: Queues screenshot tasks into the processing pipeline.


take-screenshots.php

Schedule: Processes queue continuously
Purpose: Actually captures screenshots using Chrome PHP (headless Chromium).

Dependencies: chrome-php/chrome library for headless browser rendering.


sites-add-to-queue.php

Schedule: Called by site-updates cycle
Purpose: Rebuilds the suma_cron queue when empty.

Behavior:

  1. Checks if suma_cron table is empty
  2. Inserts all active (non-archived) sites into queue
  3. Randomizes order to distribute load

Maintenance Scripts

reconnect-main-wp.php

Schedule: Every 30 minutes
Purpose: Attempts to reconnect disconnected MainWP child sites.

Behavior:

  1. Identifies disconnected sites from MainWP
  2. Attempts reconnection via MainWP API
  3. Logs results for the disconnected report

update_cloudflare.php

Schedule: Daily
Purpose: Syncs Cloudflare zone data for managed sites.

Behavior:

  1. Queries Cloudflare API for all zones in account
  2. Updates suma_sites.cf_zone_id for matching domains
  3. Verifies DNS/proxy configuration

# Site updates (every 5 minutes)
*/5 * * * * /usr/bin/php /path/to/manage/cron/site-updates.php

# MainWP reconnection (every 30 minutes)
*/30 * * * * /usr/bin/php /path/to/manage/cron/reconnect-main-wp.php

# Uptime monitoring (every 15 minutes)
*/15 * * * * /usr/bin/php /path/to/manage/cron/uptime-robot.php

# Daily checks (midnight)
0 0 * * * /usr/bin/php /path/to/manage/cron/daily-site-check.php

# Daily reports (6 AM)
0 6 * * * /usr/bin/php /path/to/manage/cron/daily-git-reports.php
0 6 * * * /usr/bin/php /path/to/manage/cron/daily-disconnected-report.php
0 6 * * * /usr/bin/php /path/to/manage/cron/added-deleted-plugins-report.php

# Daily data sync
0 2 * * * /usr/bin/php /path/to/manage/cron/update-servers.php
0 3 * * * /usr/bin/php /path/to/manage/cron/check-for-new-sheets-projects.php
0 4 * * * /usr/bin/php /path/to/manage/cron/update_cloudflare.php
0 5 * * * /usr/bin/php /path/to/manage/cron/jetpack-protect.php

# Weekly reports (Monday 7 AM)
0 7 * * 1 /usr/bin/php /path/to/manage/cron/paid-inactive-plugins-report.php
0 7 * * 1 /usr/bin/php /path/to/manage/cron/unlicensed-plugin.php

# Weekly screenshots (Sunday 2 AM)
0 2 * * 0 /usr/bin/php /path/to/manage/cron/generate_screenshots.php

Troubleshooting

Script Fails Silently

  1. Check wp-content/debug.log for PHP errors
  2. Verify WordPress can bootstrap: php -r "require 'wp-load.php'; echo 'OK';"
  3. Ensure database connectivity from cron environment

Site Updates Stuck

  1. Check suma_cron table for stale entries
  2. Verify MainWP child sites are connected
  3. Clear queue: TRUNCATE TABLE suma_cron;
  4. Re-queue: Run sites-add-to-queue.php manually

Harvest Sync Timeout

  1. The sync takes 10+ minutes due to 10-second API delays
  2. Ensure PHP max_execution_time is set to 0 (unlimited) for CLI
  3. Check Harvest API credentials in plugin settings

Screenshot Failures

  1. Verify Chrome/Chromium is installed on server
  2. Check chrome-php/chrome can launch headless browser
  3. Ensure sufficient memory for rendering (512MB+ recommended)