<?php
// This file is deprecated but kept as a backup trigger.
// It simply wakes up the new process_tasks.php worker.

require_once __DIR__ . '/vendor/autoload.php';
$config = require __DIR__ . '/config.php';

echo "[Cron Legacy] Triggering traffic-driven worker...\n";

$siteUrl = $config['site_url'] ?? '';
if ($siteUrl) {
    $parts = parse_url($siteUrl);
    $host = $parts['host'] ?? 'localhost';
    $scheme = $parts['scheme'] ?? 'http';
    $port = $parts['port'] ?? ($scheme === 'https' ? 443 : 80);
    $path = rtrim($parts['path'] ?? '/', '/') . '/process_tasks.php';
    $query = "?key=" . ($config['cron_secret'] ?? '');
    
    $fp = @fsockopen(($scheme === 'https' ? 'ssl://' : '') . $host, $port, $errno, $errstr, 2);
    if ($fp) {
        $out = "GET " . $path . $query . " HTTP/1.1\r\n";
        $out .= "Host: " . $host . "\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp, $out);
        fclose($fp);
        echo "Triggered.\n";
    } else {
        echo "Failed: $errstr\n";
    }
} else {
    echo "SITE_URL not set.\n";
}
