Is there any way to know if a php script is running in cli mode?
问题 ... or the other way around, is there any way to know if a php script is running inside a web server? 回答1: http://www.php.net/manual/en/function.php-sapi-name.php function is_cli() { return php_sapi_name() === 'cli'; } 回答2: Typically, when running in CLI mode, the superglobals $argv and $argc will be set, and many of the typical contents of $_SERVER (e.g. request method) won't be available. In addition, pre-defined console streams such as STDIN , STDOUT and STDERR will be set up. 回答3: You