PHP: Detect if you are outputting to the CLI
I needed to know if my PHP was outputting to the CLI in text mode, or to a browser in HTML mode. The following simple function will tell you if you are in CLI mode.
function is_cli() {
if (php_sapi_name() == 'cli') {
return true;
}
return false;
}