You can do this by checking the value of the constant PHP_SAPI.
If it is "cli", is running on the command line.
Example:
if (PHP_SAPI === 'cli') {
// Está na linha de comando
} else {
// Está rodando no via servidor
}
Note: When the script is running on a server, the values returned by the constant PHP_SAPI or the function php_sapi_name may vary according to the server. For example, when running in Apache2, the value returned will be "apache2handler", if you use the built-in server PHP, the value returned is "cli-server". But the value returned when using on the command line is always "cli".
Check if PHP is running and the version: php --version
– Antonio Alexandre
@Antonioalexandre See the PHP version I already know :p. The question is whether it is running on the command line or not...
– Wallace Maxters