Skip to content

Instantly share code, notes, and snippets.

@ryanhs
Created August 2, 2021 14:34
Show Gist options
  • Save ryanhs/fd6bfcf7dd741ebe33ed1459f7dc0a83 to your computer and use it in GitHub Desktop.
Save ryanhs/fd6bfcf7dd741ebe33ed1459f7dc0a83 to your computer and use it in GitHub Desktop.
is_cli.php
<?php
function is_cli() {
if ( defined('STDIN') ) return true;
if ( php_sapi_name() === 'cli' ) return true;
if ( array_key_exists('SHELL', $_ENV) ) return true;
if ( empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) return true;
if ( !array_key_exists('REQUEST_METHOD', $_SERVER) ) return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment