1. Problem

When running llm_reviews.php from the server (CLI), the script cannot determine the tenant. Normally, config.php gets it from $_SERVER['HTTP_HOST'], but in CLI there is no HTTP host.

2. Solution

Inject the tenant domain into $_SERVER['HTTP_HOST'] when the script runs in CLI. This can be done either by passing it as a command-line argument.

3. Implementation

In crons/llm_reviews.php, before requiring config.php:

if (PHP_SAPI === 'cli') {
    $_SERVER['HTTP_HOST'] = getenv('TENANT') ?: ($argv[1] ?? null);
    if (!$_SERVER['HTTP_HOST']) {
        fwrite(STDERR, "Missing TENANT (env) or argument <domain>.\\n");
        exit(1);
    }
}

Then, config/config.php reads $_SERVER['HTTP_HOST'] and loads the correct tenant configuration.

4. Example with Cron

A cron job like:

0 0 * * * /usr/bin/php /var/www/app/crons/llm_reviews.php escorts-cdmx.com >/dev/null 2>&1

5. Result

Each night the cron executes, the tenant-specific configuration is loaded, and the script successfully processes one random profile for review creation. ✅