The drupal CLI is only available after the bootstrap sequence started. Do you want to use `function_exists('drupal_is_cli')` or any other function?