`php_sapi_name() == 'cli'`   

as seen here: http://php.net/manual/en/function.php-sapi-name.php