... or the other way around, is there any way to know if a php script is running inside a web server?
http://www.php.net/manual/en/function.php-sapi-name.php
function is_cli() { return php_sapi_name() === 'cli'; }