I'm using the following command to execute a PHP file via cron
php -q /home/seilings/public_html/dvd/cron/mailer.php
The problem is that I Have a file that's included in the execution that determines which config to load.... such as the following:
if (!strstr(getenv('HTTP_HOST'), ".com")) {
$config["mode"] = "local";
} else {
$config["mode"] = "live";
}
The cron is loading the LOCAL config when it should be loading the LIVE config. I've tried using the http:// URL to the file instead of the absolute path but it didn't find the file. Do I need to change the command to use a URL within it?
Another simple solution:
cron:
php -q /home/seilings/public_html/dvd/cron/mailer.php local
php:
if (!empty($argv[0])) {
$config["mode"] = "local";
} else {
$config["mode"] = "live";
}
Use this php_sapi_name()
to check if the script was called on commandline:
if (php_sapi_name() === 'cli' OR !strstr(getenv('HTTP_HOST'), ".com")) {
$config["mode"] = "local";
} else {
$config["mode"] = "live";
}
If you want to use "live" on the commandline use this code:
if (php_sapi_name() === 'cli' OR strstr(getenv('HTTP_HOST'), ".com")) {
$config["mode"] = "live";
} else {
$config["mode"] = "local";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With