Is there any way to know if a php script is running in cli mode?

command-line-interface, php

Solution

http://www.php.net/manual/en/function.php-sapi-name.php

function is_cli()
{
    return php_sapi_name() === 'cli';
}

Problem

... or the other way around, is there any way to know if a php script is running inside a web server?

Original source

Related problems