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.
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.
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.
A cron job like:
0 0 * * * /usr/bin/php /var/www/app/crons/llm_reviews.php escorts-cdmx.com >/dev/null 2>&1
$argv[1]
is escorts-cdmx.com
.$_SERVER['HTTP_HOST']
is set to that domain.config.php
loads the correct tenant’s DB connection.llm_reviews_create()
.Each night the cron executes, the tenant-specific configuration is loaded, and the script successfully processes one random profile for review creation. ✅