The web host that my website is hosted on uses FastCGI, and so Director::is_cli() always returns false, even when running a script using cron. This is because php_sapi_name() always returns "cgi-fcgi", regardless of where php is called from.
Is there any reliable way to get is_cli() working properly? I've tried every method that I can find on the internet, including checking various $_SERVER array entries (e.g., isset($_SERVER['HTTP_USER_AGENT'])), but all of them fail.
I finally found the solution [url=http://www.silverstripe.org/general-questions/show/16560#post319504]here[/url]. Simply set cron to call "php-cli" instead of "php". For example, use:
php-cli sapphire/cli-script.php /dev/tasks/ProcessJobQueueTask