I need to determine whether the PHP file is being loaded via cron or command line within the code. How can I do this?
You can check the PHP_SAPI constant to check if the CLI interpreter is being used:
PHP_SAPI
$is_cli= PHP_SAPI == 'cli';