How to differentiate between http and cli requests?

command-line-interface, http, php, request

Solution

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

<?php
echo PHP_SAPI;
echo php_sapi_name();
?>

Problem

The title is quiet straightforward. I have to know on server side if the script called through HTTP request or by command line. I could examine the `$_SERVER['argv']` or `$_SERVER['argc']`. What is the pragmatic way to do that?

Original source