I now to ways to detect weather php script runs in cli or web server mode:
if (defined('STDIN'))
or:
if (isset($argc))
Do they equally reliable or one of them is more ?
Neither. Check the value returned from php_sapi_name().
php_sapi_name()