Determine Whether A PHP Script Is Running In A Command Line

For some particular cron jobs, it was quite necessary to determine whether the PHP script is running in a command line or called via HTTP. For this I used the PHP function PHP-sapi-name wrapped in a custom function:

function is_cli()
    return php_sapi_name() === 'cli';
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn