Detects whether the current script is running in a command-line environment.
function drupal_is_cli() { return !isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0); }