Created
August 2, 2021 14:34
-
-
Save ryanhs/fd6bfcf7dd741ebe33ed1459f7dc0a83 to your computer and use it in GitHub Desktop.
is_cli.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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